Posted on 2009-08-31 03:27:41-07 by tonyc in response to 11380
Re: Creating a square image from a rectangular image

You need to create a new image and paste the existing image into it:

my $inim = ...; # some image we want to make square my $outim = Imager->new(xsize => 400, ysize => 400); my $ypos = int((400 - 250) / 2); $outim->box(filled => 1, color => $back_color, ymax => $ypos-1); $outim->paste(src => $inim, top => $ypos); $outim->box(filled => 1, color => $back_color, ymin => $ypos + 250); $outim->write(file => "output.png"); # or whatever you want to do with it

Alternatively, if the source image can be partly transparent, you might want to fill the output image with your background color and use the rubthrough() method:

$outim->box(filled => 1, color => $back_color); $outimg->rubthrough(src => $inim, tx => $ypos);
Direct Responses: 11382 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.