Test::Image::GD(3pm)
π NAME π
Test::Image::GD β bestie, it's a whole module for testing images using GD β¨
πΈ SYNOPSIS πΈ
okay so first things first, here's the vibe:
use Test::More plan => 1;
use Test::Image::GD;
cmp_image('test.gif', 'control.gif', '... these images should match');
# or
my $test = GD::Image->new('test.gif');
my $control = GD::Image->new('control.gif');
cmp_image($test, $control, '... these images should match');
# some other test functions ...
size_ok('camel.gif', [ 100, 350 ], '... the image is 100 x 350");
height_ok('test.gif', 200, '... the image has a height of 200');
width_ok('test.gif', 200, '... the image has a width of 200');
π¦ DESCRIPTION π¦
so basically this module is made for testing custom graphics, and the way it works is it tries to "visually" compare the images β which is a fancy way of saying it ignores all the invisible differences, like color palettes and metadata. like, if it looks the same, it IS the same, periodt π
it also comes with some extra little functions to check the size of the image. size check? slayed. π
β¨ FUNCTIONS β¨
π cmp_image ($got, $expected, $message)
this one tells you whether the two images are gonna look different, and it does that by ignoring differences in the order of colors in the color palette and other invisible changes. no cap, invisible stuff doesn't count here.
ngl the best part: both $got and $expected can be either instances of GD::Image or a file handle or a file path (both are valid parameters to the GD::Image constructor). so many options, we love to see it π«Ά
π size_ok ($got, [ $width, $height ], ?$message)
checks if an image is a certain size. iconic.
and same deal as the cmp_image function β the $got parameter can be either an instance of GD::Image or a file handle or a file path (all are valid parameters to the GD::Image constructor). β¨
π height_ok ($got, $height, ?$message)
checks if an image is a certain height. main character energy fr.
as with the cmp_image function, the $got parameter can be either an instance of GD::Image or a file handle or a file path (all are valid parameters to the GD::Image constructor). π
πΈ width_ok ($got, $width, ?$message)
checks if an image is a certain width. she's giving precise π
as with the cmp_image function, the $got parameter can be either an instance of GD::Image or a file handle or a file path (all are valid parameters to the GD::Image constructor). π¦
π§ TO DO π§
Add more functions
so rn this module serves a very basic need of mine, but lowkey I'm sure that as I start writing more tests against images I'm gonna find a need for other testing functions. any suggestions are welcome bestie, slide into my DMs π¬
π BUGS π
none that I am aware of. of course, if you find a bug, let me know, and I will be sure to fix it. fr fr. π
π CODE COVERAGE π
I use Devel::Cover to test the code coverage of my tests, and below is the Devel::Cover report on this module test suite. look at those numbers, we ate. π₯
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
Test/Image/GD.pm 100.0 91.7 63.6 100.0 100.0 100.0 93.7
---------------------------- ------ ------ ------ ------ ------ ------ ------
Total 100.0 91.7 63.6 100.0 100.0 100.0 93.7
---------------------------- ------ ------ ------ ------ ------ ------ ------
π SEE ALSO π
the "compare" function of "GD::Image" class β that's literally how this "cmp_image" is implemented. iykyk π
β AUTHOR β
Stevan Little, <stevan@iinteractive.com>
π COPYRIGHT AND LICENSE π
Copyright 2005 by Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page bestie, go forth and test those images πβ¨
perl v5.30.3 Β· 2020-07-29 Β· Test::Image::GD(3pm) β mwah, ty for reading, ily, bye π«Άπ
π¦ where this page comes from
- debian bookworm: libtest-image-gd-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-image-gd-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libtest-image-gd-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-image-gd-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-image-gd-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-image-gd-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms