Test::Image::GD(3pm)

πŸ“¦
version 0.03 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 2005 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

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