Page 1 of 1

Can't seem to replicate PerlMagick on the command line

Posted: 2013-02-27T09:47:09-07:00
by mrshake
Hello Ladies and Gents,

I'm hitting a bit of a wall, and I hope I can get your assistance!

I've been tasked with re-writing a perl script in Python, and that Perl script uses ImageMagick/PerlMagick to manipulate images.

I've tried using Python's PIL Library, but its not capable of doing one of the tasks as well as ImageMagick.. so in an effort to be quick and simple, I'm working on calling the convert command on the command line from Python to accomplish this one task.

The task is as follows:

Taking a LARGE .tif file and shrinking it, rotating it -5 degrees, making the background transparent, and saving it as a gif (and no, I can't change these requirements)

My Perl script did this quite well, but trying to replicate that on the command line is proving difficult.. here is what I have:
Image

Here is the PerlMagick Code:

Code: Select all

my $agent4=Image::Magick->new();
my $x4=$agent4->Read($workingfile);
warn $x4 if $x4;
$agent4->Resample(density=>'300x300');
$agent4->Rotate(degrees=>'-5', background=>'white');
$agent4->Resize(geometry=>'194x233');
$agent4->Border(width=>'15.5', height=>'11.5', bordercolor=>'white');
$agent4->FloodfillPaint(geometry=>'0x0', channel=>'All', fill=>'transparent');
$agent4->WriteImage($wf3);
$agent4->WriteImage($wf6);
$agent4->WriteImage($wf4);
Command Line Attempt:

Code: Select all

convert agentphoto.tif -resample 300x300 -background none -geometry 194x233 -bordercolor white -border 15.5x11.5 -transparent white -rotate -5 test.gif
I've also tried Flood Fill and Opaque to change the white border to transparent. The reason for the white border is to "blend" the edges into the white background the image will be dropped on on the web.

Thoughts? I have pretty strict set of requirements regarding edge smoothness, file format, and where it goes on the web space.

Re: Can't seem to replicate PerlMagick on the command line

Posted: 2013-02-27T11:06:01-07:00
by fmw42
Can you post a link to your original tiff image? Also what version of IM and on what platform?

This should work

convert image -resample 300x300 -background none -rotate 5 result.png

I suggest you try png rather than gif if the colors change, since gif is limited to 256 colors, unless you want the smaller image size. Then gif or PNG8: will be ok.

Your -geometry is not likely to do anything, nor do you want to add a border unless you want it to be transparent. Then

convert image -resample 300x300 -bordercolor none -border 15 -background none -rotate 5 result.png

Note fractional pixels in the border will be truncated or rounded to the nearest whole pixel. IM cannot add fractional pixels.

The color "none" is the same as the color "transparent". Both are valid IM color specifications for fully transparent pixels.

Re: Can't seem to replicate PerlMagick on the command line

Posted: 2013-02-27T14:12:16-07:00
by mrshake
fmw42 wrote:Can you post a link to your original tiff image? Also what version of IM and on what platform?

This should work

convert image -resample 300x300 -background none -rotate 5 result.png

I suggest you try png rather than gif if the colors change, since gif is limited to 256 colors, unless you want the smaller image size. Then gif or PNG8: will be ok.

Your -geometry is not likely to do anything, nor do you want to add a border unless you want it to be transparent. Then

convert image -resample 300x300 -bordercolor none -border 15 -background none -rotate 5 result.png

Note fractional pixels in the border will be truncated or rounded to the nearest whole pixel. IM cannot add fractional pixels.

The color "none" is the same as the color "transparent". Both are valid IM color specifications for fully transparent pixels.
Original:
Image

PNG is not an option due to browser issues. System is Windows, IM is 6.8.3

Re: Can't seem to replicate PerlMagick on the command line

Posted: 2013-02-27T14:19:11-07:00
by snibgo
That's a JPG, not the original TIF.

Re: Can't seem to replicate PerlMagick on the command line

Posted: 2013-02-27T14:21:24-07:00
by fmw42
two problems

1) you have uploaded a JPG rather than your tiff
2) the JPG (and presumably the tiff) is CMYK rather than sRGB and needs to use the imbedded profile to convert to sRGB properly since gif does not support CMYK

This works for me.

convert 01048-Woodside-L_zps9eeb82e8.jpg -profile /Users/fred/images/Profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/Profiles/sRGB.icc -resample 300x300 -background none -rotate 5 result.gif