logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Test::Image::GD - A module for testing images using GD

Author

       Stevan Little, <stevan@iinteractive.com>

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.

Code Coverage

       I use Devel::Cover to test the code coverage of my tests, below is the Devel::Cover report on this module
       test suite.

        ---------------------------- ------ ------ ------ ------ ------ ------ ------
        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
        ---------------------------- ------ ------ ------ ------ ------ ------ ------

Description

       This module is meant to be used for testing custom graphics, it attempts to "visually" compare the
       images, this means it ignores invisible differences like color palettes and metadata. It also provides
       some extra functions to check the size of the image.

Functions

cmp_image($got,$expected,$message)
           This  function  will tell you whether the two images will look different, ignoring differences in the
           order of colors in the color palette and other invisible changes.

           Both $got and $expected can be either instances of "GD::Image" or either a file handle or a file path
           (both are valid parameters to the "GD::Image" constructor).

       size_ok($got,[$width,$height],?$message)
           This function will check if an image is a certain size.

           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).

       height_ok($got,$height,?$message)
           This function will check if an image is a certain height.

           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)
           This function will check if an image is a certain width.

           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).

Name

       Test::Image::GD - A module for testing images using GD

See Also

       The "compare" function of "GD::Image" class, that is how this "cmp_image" is implemented.

Synopsis

         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');

To Do

       Add more functions
           This  module  currently  serves a very basic need of mine, however, I am sure as I start writing more
           tests against images I will find a need for other testing functions. Any suggestions are welcome.

See Also