Imager::Test(3pm)
π NAME π
ok so Imager::Test β it's the shared little bag of functions everybody uses when they're testing Imager. that's the whole vibe, bestie.
β¨ SYNOPSIS β¨
use Imager::Test 'diff_text_with_nul';
diff_text_with_nul($test_name, $text1, $text2, @string_options);
π¦ DESCRIPTION π¦
This is, like, the communal pile of functions used for testing Imager. it's giving "shared test-toolbox energy" π§°
Some of these are only ever gonna be useful if you're testing Imager itself. others lowkey should be handy when you're testing your own modules that happen to use Imager. so don't feel weird about borrowing, iykyk.
No functions are exported by default. periodt. you gotta ask for what you want.
π FUNCTIONS π
πΈ Test functions πΈ
is_color1($color, $grey, $comment)β checks whether the first channel of$colormatches$grey. just channel one. that's it. slay.is_color3($color, $red, $green, $blue, $comment)β checks whether$colormatches the given($red, $green, $blue).is_color4($color, $red, $green, $blue, $alpha, $comment)β checks whether$colormatches the given($red, $green, $blue, $alpha).is_fcolor1($fcolor, $grey, $comment)is_fcolor1($fcolor, $grey, $epsilon, $comment)β checks whether$fcolor's first channel is within$epsilonof ($grey). β¨ in the first form$epsilonis taken as0.001.is_fcolor3($fcolor, $red, $green, $blue, $comment)is_fcolor3($fcolor, $red, $green, $blue, $epsilon, $comment)β checks whether$fcolor's channels are all within$epsilonof($red, $green, $blue). in the first form$epsilonis taken as0.001.is_fcolor4($fcolor, $red, $green, $blue, $alpha, $comment)is_fcolor4($fcolor, $red, $green, $blue, $alpha, $epsilon, $comment)β checks whether$fcolor's channels are all within$epsilonof($red, $green, $blue, $alpha). first form?$epsilonis0.001. yes bestie, again.is_image($im1, $im2, $comment)β checks whether the two images have the same content. both images have to be defined, and they need the same width, height, channels, and the same color in every single pixel. the color comparison happens at 8-bits per pixel. it does not check the color representation β so direct vs paletted, bits per sample, none of that is looked at π. this is equivalent tois_image_similar($im1, $im2, 0, $comment).is_imaged($im, $im2, $comment)is_imaged($im, $im2, $epsilon, $comment)β checks whether the two images have the same content but at the double/sample level.$epsilondefaults to the platformDBL_EPSILONmultiplied by four. tiny tolerance, big drama πis_image_similar($im1, $im2, $maxdiff, $comment)β checks whether the two images have similar content. both must be defined and have the same width, height and channels. it sums the squares of the differences of each sample, and that sum has to be less than or equal to$maxdifffor the test to pass. color comparison is at 8-bits per pixel, and again the color representation (direct vs paletted, bits per sample) is not checked.isnt_image($im1, $im2, $comment)β checks that the two images are different. this exists for regression tests where something (like the text output of"0") produced no change but totally should have produced a change. not me filing that bug πtest_colorf_gpix($im, $x, $y, $expected, $epsilon, $comment)β grabs the pixel($x,$y)out of the low-level image$imand compares it against the floating point color$expected, with a tolerance of epsilon.test_color_gpix($im, $x, $y, $expected, $comment)β grabs the pixel($x,$y)out of the low-level image$imand compares it against the floating point color$expected.test_colorf_glin($im, $x, $y, $pels, $comment)β grabs the floating point pixels($x, $y)-[$x+@$pels, $y]from the low level image$imand compares them against@$pels.is_color_close3($color, $red, $green, $blue, $tolerance, $comment)β checks whether$color's first three channels are within$toleranceof($red, $green, $blue).
π§ Test suite functions π§
these ones run one or more tests, and they're typically used to test various parts of Imager's implementation. the heavy lifters fr fr.
image_bounds_checks($im)β tries to write to various pixel positions outside the edge of the image, to make sure it fails in those locations. any new image type should pass these tests. does 16 separate tests. sixteen!! πmask_tests($im, $epsilon)β runs a standard set of mask tests on the OO image$im. does 24 separate tests.diff_text_with_nul($test_name, $text1, $text2, @options)β creates 2 test images, writes$text1to the first one and$text2to the second one using thestring()method. each call adds 3"ok"/"not ok"lines to the output of the test script. extra options you should supply include the font and either a color or channel parameter. this was explicitly created for regression tests on#21770. historical icon behavior π₯std_font_tests({ font => $font })β runs the standard font interface tests.std_font_test_count()β tells you the number of tests thatstd_font_tests()performs.
π«Ά Helper functions π«Ά
test_image_raw()β returns a150x150x3Imager::ImgRawtest image.test_image()β returns a150x150x38-bit/sample OO test image. Name:"basic".test_image_16()β returns a150x150x316-bit/sample OO test image. Name:"basic16"test_image_double()β returns a150x150x3double/sample OO test image. Name:"basic_double".test_image_gray()β returns a150x150single channel OO test image. Name:"gray".test_image_gray_16()β returns a150x15016-bit/sample single channel OO test image. Name:"gray16".test_image_mono()β returns a150x150bilevel image that passes theis_bilevel()test. Name:"mono".test_image_named($name)β returns one of the other test images above, based on the name.color_cmp($c1, $c2)β performs an ordering of 3-channel colors (like<=>).colorf_cmp($c1, $c2)β performs an ordering of 3-channel floating point colors (like<=>).
π AUTHOR π
Tony Cook <tony@develop-help.com> β the main character of this page, honestly π
okay that's the whole page bestie, go write some tests π β¨
this little gem is Imager::Test(3pm) from the Perl documentation, delivered by perl v5.42.3 and dated 2026-08-19 β mwah, hope that helped ππ¦
π¦ where this page comes from
- ubuntu stonking: libimager-perl 1.035+dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms