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:18:47-07 by richardmortimer
Creating a square image from a rectangular image
Is it possible with Imager to take an image that is (for example) 250x400 px and convert it to an image that is 400x400 px with the 250x400 image in the centre, and the upper and lower 'band' as a specified colour?

I've tried applying a scale translation, but I can't seem to get the logic after that. Not looking for a solution, just some guidance!

Thanks

Richard

Direct Responses: 11381 | Write a response
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
Posted on 2009-08-31 03:36:18-07 by richardmortimer in response to 11381
Re: Creating a square image from a rectangular image
Thanks for the fast response - creating a new image went through my mind, but I wasn't aware of the 'paste' function.

Not sure if it's worth adding this as suggestion for a new function?

Cheers

Richard
Direct Responses: Write a response