Can't seem to replicate PerlMagick on the command line

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

Can't seem to replicate PerlMagick on the command line

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
mrshake
Posts: 35
Joined: 2008-11-18T08:18:51-07:00

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

That's a JPG, not the original TIF.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
Post Reply