Page 1 of 1
Trim() not working
Posted: 2008-07-26T08:43:19-07:00
by clark238
Help! I'm going crazy... Using 6.4.1 and I can't get Trim() to work. All it does is return the same size image with the background color replaced with transparency. I would hope and want this function to crop the image to 208x104 (size of the bounding box). Here are my input and output files:
input.jpg
output.gif (view image properties to see that it's still 280x280)
Here's my code:
Code: Select all
$image=Image::Magick->new;
$file_input = "input.jpg;
$file_output = "output.gif";
$image->ReadImage($file_input);
unlink($file_input);
$image = $image->[0]; #grab first image in case it's an animation
$image->Trim();
$image->Write($file_output);
undef $image;
If I get the 'bounding-box' property before I do the Trim(), I get "208x104+32+96" and if I do it after the Trim() I get 208x104+0+0
This doesn't work either:
Code: Select all
$box = $image->Get('bounding-box');
$image->Crop(geometry=>$box);
Thanks in advance!
Re: Trim() not working
Posted: 2008-07-26T09:16:42-07:00
by wrnelson55
I have had success with “Crop” by coding the statement this way.
It requires a little math to get the variable values, but it works for me.
width = width of the cropped area
height = height of the cropped area
x = horizontal offset of the cropped area from the original
y = vertical offset of the cropped area from the original
$i = $image->Crop( width=>$scaleSizeX, height=>$scaleSizeY,
x=>$scaleOffsetX, y=>$scaleOffsetY );
Re: Trim() not working
Posted: 2008-07-26T10:33:56-07:00
by clark238
$i = $image->Crop( width=>$scaleSizeX, height=>$scaleSizeY, x=>$scaleOffsetX, y=>$scaleOffsetY );
Thanks, but that doesn't work either.
I found and tried Chop() but that behaves like Resize(). I can't find any functions that will allow me to change the canvas size (photoshop term) without affecting the image. I can't Trim, Crop or Chop pixels off the top, sides or bottom. In what version could you do $image->Crop(0x0) ? Maybe I'll revert to that and try it.
This is driving me crazy! what am I doing wrong?
BTW, I'm running perl on Windows if that makes a difference
Re: Trim() not working
Posted: 2008-07-26T10:41:32-07:00
by wrnelson55
I am running ImageMagick-6.4.1 and the PerlMagick that installed with it on Linux (Mandriva)
sorry that did not work, good luck
Re: Trim() not working
Posted: 2008-07-26T10:49:41-07:00
by el_supremo
I can't find any functions that will allow me to change the canvas size
I don't know Perl but on the command line it is the +repage option and in C you would use the statement:
Code: Select all
MagickResetImagePage(magick_wand,"");
[/code
Pete
Re: Trim() not working SOLUTION!!!
Posted: 2008-07-26T11:01:14-07:00
by clark238
Wow, I'm bald at this point, but I figured it out...
You just need to Trim() and then reset the canvas size:
Code: Select all
$image->Trim();
$image->Set(page=>'0x0+0+0');
[code]
HUGE RELIEF! :D
Thanks to everyone who replied. Double thanks to El_supremo who got me googling for "page"!