Image::Math::Constrain

Scaling math used in image size constraining (such as thumbnails)
Download

Image::Math::Constrain Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Adam Kennedy
  • Publisher web site:
  • http://search.cpan.org/~adamk/

Image::Math::Constrain Tags


Image::Math::Constrain Description

Scaling math used in image size constraining (such as thumbnails) Image::Math::Constrain is a Perl module with scaling math functions used in image size constraining (such as thumbnails).SYNOPSIS use Image::Math::Constrain; # Create the math object my $math = Image::Math::Constrain->new(64, 48); # Get the scaling values for an arbitrary image my $Image = My::Image->load("myimage.jpg"); my $scaling = $math->constrain($Image->width, $Image->height); die "Don't need to scale" if $scaling->{scale} == 1; # Returns the three values as a list when called in array contect my ($width, $height, $scale) = $math->constrain(800, 600); # There are lots of different ways to specify the constrain # Constrain based on width only $math = Image::Math::Constrain->new(100, 0); # Constrain based on height only $math = Image::Math::Constrain->new(0, 100); # Or you can provide the two values by ARRAY ref $math = Image::Math::Constrain->new( ); # Constrain height and width by the same value $math = Image::Math::Constrain->new(100); # Various string forms to do the same thing $math = Image::Math::Constrain->new('constrain(800x600)'); $math = Image::Math::Constrain->new('300x200'); $math = Image::Math::Constrain->new('300w200h'); $math = Image::Math::Constrain->new('100w'); $math = Image::Math::Constrain->new('100h'); # Serialises back to 'constrain(800x600)'. # You can use this to store the object if you wish. my $string = $math->as_string;There are a number of different modules and systems that constrain image sizes, such as thumbnailing. Every one of these independantly implement the same logic. That is, given a width and/or height constraint, they check to see if the image is bigger than the constraint, and if so scale the image down proportionally so that it fits withint the constraints.Of course, they all do it slightly differnetly, and some do it better than others.Image::Math::Constrain has been created specifically to implement this logic once, and implement it properly. Any module or script that does image size constraining or thumbnailing should probably be using this for its math. Requirements: · Perl


Image::Math::Constrain Related Software