I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
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