Selenium::Screenshot::CanPad - Provides subs for coercing two images to the exact width and height


version 0.08


    my $tall = Imager->new( xsize => 10, ysize => 20 );
    my $wide = Imager->new( xsize => 20, ysize => 10 );

    my ($square1, $square2) = Selenium::Screenshot::CanPad->coerce_image_size(
        $tall, $wide

    is( $square1->getwidth , $square2->getwidth , 'Same width'  );
    is( $square1->getheight, $square2->getheight, 'Same height' );


For "compare" in Selenium::Screenshot to be able to compare two Imager objects, the objects must be exactly the same height and width. This package provides a function "coerce_image_size" that does exactly that: given two Imager objects, it returns an ARRAY of two Imager objects that are the same size.

It does this by getting the largest width and height from either image, and adding blck padding to the bottom and/or right of either image if necessary.


coerce_image_size ( $image1, $image2 )

This sub has two required arguments: two Imager objects. It uses the largest width and height of either image, and pad both of them until both images are the same size as the largest image. The example in the synopsis is probably most helpful: given a 10x20 image and a 20x10 image, this sub would return two 20x20 images, each padded accordingly.

cmp_image_dims ( $image1, $image2 );

This sub has two required arguments: two Imager objects. If both images have the exact same height and width, it will return truthy; otherwise it will return falsy.

This is a public function because of the way Selenium::Screenshot is set up - its "_set_opponent" in Selenium::Screenshot subroutine needs to know whether or not it should be overwriting the png attr of the object, as it's a isa = 'rwp'> attribute. If we were keep this sub private to this role, the consuming role would have to overwrite its attribute unnecessarily.


Please see those modules/websites for more information related to this module.


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.


Daniel Gempesaw <>


This software is copyright (c) 2015 by Daniel Gempesaw.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.