I'm dying here... Trying to Rotate and resize, not going wel

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

I'm dying here... Trying to Rotate and resize, not going wel

Post by mrshake »

Hey guys, First time poster here...

I've been trying for about 2 weeks to put togeather a script that will rotate and resize images.

Details:

Start -
600x750px tif

End -
Needs to be 300dpi
Needs to be 225x256
Needs to be gif
Needs to be rotated -5 degrees
Needs to have a "border" around it so that the corners of the rotated image are 11px vertical and 16 px horizontal from the edge of the graphic.
Needs to have transparent background
Edges need to be clean


Here is what I'm doing currently thats not working:

Code: Select all

$x4 = $agent4->Resample(density=>'300x300');
$x4 = $agent4->AffineTransform(rotate=>'-5', interpolate=>'Mesh', background=>'none');
$x4 = $agent4->Scale(geometry=>'214x243');
$x4 = $agent4->Border(geometry=>'11x16', bordercolor=>'none'	);
currently, everything seems to be fine, except the final image size never ends up exactly 225x256

thoughts?
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by el_supremo »

The problem is that the result of the scale command is a 202x243 image, so you are adding the wrong amount to the edges.
Furthermore, both dimensions require that you add an odd number of lines to each edge. To get around that you have to "splice" a row and a column of one pixel before (or after) doing the border.
This is the test I did on the command line:

Code: Select all

convert -density 300x300 -units pixelsperinch test.gif  -background none -rotate -5 -scale 214x243 -splice 1x1 -border 11x6 test.png
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by mrshake »

thanks for the help!! Thats getting me very close...

Here is what I need in the end.

I need the image rotated -5 degrees, with 11pixes top and bottom and 16 pixels on each side border. I'm apparently not getting the concept or am math challenged here, because I'm not figuring it out myself.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by el_supremo »

It would probably be easier to make a background image of the final size that you require and composite the rotated image on top.

Code: Select all

convert -density 300x300 -units pixelsperinch test.gif  -background none -rotate -5 -scale 214x243 -size 225x256 xc:none -gravity center -composite test.png
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by mrshake »

I was actually thinking composite would be the right thing. Forgive me here, I'm trying to translate from CLI to PerlMagick... heres what I've done.. not working

$x4 = $agent4->Resample(density=>'300x300');
$x4 = $agent4->Set(units=>'pixelsperinch');
$x4 = $agent4->Rotate(degrees=>'-5', background=>'none');
$x4 = $agent4->Scale(geometry=>'194x233');
$x5 = $agent5->Composite(image=>'$agent4', compose=>'over', geometry=>'15x11') or print "Compsite Failed $!";


$agent5 is a transparent PNG of the final size.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by el_supremo »

I can't test your Perl script so you'll have to post the output image so I can see what is wrong with it.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by mrshake »

Here are the original and the output images:

Here is a photoshop example of the final output
Image

Here is the background (transparent) that is the right size
Image

here is the original (its a tiff)
http://www.adamandnicole.com/gallery2/g ... /test.tiff

here is the current output
Image
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by el_supremo »

I think there's an error in your geometry spec. I think geometry=>'+15+11' will work but if not, try geometry=>'225x256+15+11'

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by mrshake »

Here is where I'm at right now.. and its getting more frustrating...

Its now not outputting the file at all

Code: Select all

print "Transform Image for Agent Website Needs ... \n";

$x4 = $agent4->Resample(density=>'300x300');
$x4 = $agent4->Set(units=>'pixelsperinch');
$x4 = $agent4->Rotate(degrees=>'-5', background=>'none');
$x4 = $agent4->Scale(geometry=>'194x233');
#$x4 = $agent4->Splice(geometry=>'16x15x12x11', gravity=>'SouthEast');
#$x4 = $agent4->Splice(geometry=>'15x11', gravity=>'NorthWest');
$x5 = $agent5->Composite(image=>'$x4', compose=>'over', geometry=>'225x256+15+11') or print "Compsite Failed $!";

print "Third Write Image... \n";

$x4=$agent4->WriteImage($workingfilegifagentws);
$x5=$agent5->WriteImage($wf2) or print "Write Failed $!\n";
the 2nd write should crate a testagentnews2.png and it is not being created, so I have no idea if its working!! GRRR
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by el_supremo »

Before you complicate matters I need to know if my suggestion worked on the original code.
Does this work??

Code: Select all

$x4 = $agent4->Resample(density=>'300x300');
$x4 = $agent4->Set(units=>'pixelsperinch');
$x4 = $agent4->Rotate(degrees=>'-5', background=>'none');
$x4 = $agent4->Scale(geometry=>'194x233');
$x5 = $agent5->Composite(image=>'$agent4', compose=>'over', geometry=>'+15+11') or print "Composite Failed $!";
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by mrshake »

Thats the problem, I'm not sure if it did. I haven't been able to test it.

looking back.. I think its never managed an output for the composite. I think the image I was looking at was the pre-composite output.
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

Re: I'm dying here... Trying to Rotate and resize, not going wel

Post by mrshake »

I turned debugging on and It appears to be a problem with the composite command.. heres the debug output

Transform Image for Agent Website Needs ...
2008-11-25T08:52:22-06:00 0:01 0.000u 6.4.1 Exception PerlMagick[2912]: Magick.xs/unknown/6456/Exception
no images defined `Composite'
Third Write Image...
2008-11-25T08:52:22-06:00 0:01 0.000u 6.4.1 Exception PerlMagick[2912]: Magick.xs/unknown/12348/Exception
no images defined `Image::Magick'
2008-11-25T08:52:22-06:00 0:01 0.000u 6.4.1 Exception PerlMagick[2912]: Magick.xs/unknown/12348/Exception
no images defined `Image::Magick'
Script Complete
Post Reply