Page 1 of 1

I've had no luck in the Perl Magic Forum.... Any thoughts?

Posted: 2010-02-08T09:49:03-07:00
by mrshake
Hello Folks,

I'm having an intermittent problem with a perl/perlmagick script I'm using to process photos for a website.

The originals come in as .tif files in either RGB or CMYK mode, sized at 600x750.

My script (along with many other things) takes this image:

1. Resamples for density
2. rotates the image 5 degrees
3. sets the background (due to rotation) to white
4. Sets the size to 194x233
5. Saves the file to png format
6. Reopens the file
7. Sets the size to 225x256
8. Read(xc:white)
9. Sets Density again
10. Sets gravity center
11. Writes file again to png again
12. Reopens the file
13. Sets Alpha to on
14. Flood Fills transparency over the white background from the rotate
15. Writs the final image as a .gif

Here is what the final image SHOULD look like:

Image

Here is the original:

Image

Here is what happens sometimes (2 problems):

Image
Image


So, the first example is horrible, the second never gets the transparency added.

The puzzling thing is, I can (sometimes) re-run the image through the process and it works fine. In fact, if the image is bad, I grab the original and run it, and within a time or two, it works fine. This is not a consistent problem. Thoughts? Debugging I Can add to the script? I'll add the code part to the next post

Re: I've had no luck in the Perl Magic Forum.... Any though

Posted: 2010-02-08T11:19:19-07:00
by snibgo
The description makes your script sound very complex. Resizing down, then up again? I suggest you post the script, with an original tif that sometimes goes wrong, and the intermediate files. Your platform and IM version may be relevant.

Here is how I would do it (without touching density, which isn't normally relevant for web work):

Code: Select all

convert 20553-Claywell-S.jpg -resize 250x250 -background none -rotate -5 output.png

Re: I've had no luck in the Perl Magic Forum.... Any though

Posted: 2010-02-08T12:33:03-07:00
by mrshake
Original Tiff, and all the subsequents are in the first post... here is the code:

Code: Select all

if ($verbose == 1) {print "Transform Image for Rep Website Step 1.......";}
my $x15 = $agent4->Resample(density=>'300x300');
my $x16 = $agent4->Set(units=>'pixelsperinch');
my $x17 = $agent4->Rotate(degrees=>'-5', background=>'white');
my $x18 = $agent4->Resize(geometry=>'194x233');
my $x19=$agent4->WriteImage($wftmp);
warn $x19 if $x19;
if ($verbose == 1) {print "Done\n";}

if ($verbose == 1) {print "Transform Image for Rep Website Step 2.......";}
my $im = Image::Magick->new();
my $bg = Image::Magick->new(size => "225x256");
my $rc = $bg->Read("xc:white");
$rc = $im->Read($wftmp);
$rc = $bg->Set(density=>'300x300');
$rc = $bg->Composite(gravity => "Center", image => $im);
$rc = $bg->Write($wf2);
warn $rc if $rc;
if ($verbose == 1) {print "Done\n";}

undef $agent1;
undef $agent2;
undef $agent3;
undef $agent4;
undef $im;
undef $bg;
undef $rc;

if ($verbose == 1) {print "Transfor Image for Rep Website Final Step.......";}
my $repfinal=Image::Magick->new();
my $agentrepx=$repfinal->Read($wf2);
warn $agentrepx if $agentrepx;
$agentrepx = $repfinal->Set(alpha=>'On');
$agentrepx = $repfinal->FloodfillPaint(geometry=>'0x0', channel=>'All', fill=>'transparent', fuzz=>'2%');
$agentrepx = $repfinal->Set(alpha=>'On');
$agentrepx = $repfinal->WriteImage($wf3);
$agentrepx = $repfinal->WriteImage($wf4);
warn $agentrepx if $agentrepx;
print SUBMITDIRECT "$wf5\n";
if ($verbose == 1) {print "Done\n";}

Re: I've had no luck in the Perl Magic Forum.... Any though

Posted: 2010-02-08T12:43:45-07:00
by mrshake
Platform is Windows Server 2003, IM version is ImageMagick-6.4.8-Q16

Re: I've had no luck in the Perl Magic Forum.... Any though

Posted: 2010-02-09T01:07:53-07:00
by snibgo
I don't speak perl, so can't help you there.

You might try the equivalent shell commands to see if they work. That would narrow down the problem.

You might try updating IM.

Your script seems to flood-fill the white border with transparent. But his shirt at the border is white, so that would cause problems.

You seem to need one image with transparent triangles, the other with white triangles and a white border. The following will do that:

Code: Select all

convert 20553-Claywell-S.jpg -density 300x300 -units pixelsperinch -background none -rotate -5 -geometry 194x233 wfTran.gif

convert -size 225x256 xc:white wfTran.gif -gravity Center -composite wfWhite.gif
(Personally, I would use PNG, to retain the anti-aliased edges.)

Re: I've had no luck in the Perl Magic Forum.... Any though

Posted: 2010-02-09T08:51:17-07:00
by mrshake
snibgo wrote:I don't speak perl, so can't help you there.

You might try the equivalent shell commands to see if they work. That would narrow down the problem.

You might try updating IM.

Your script seems to flood-fill the white border with transparent. But his shirt at the border is white, so that would cause problems.

You seem to need one image with transparent triangles, the other with white triangles and a white border. The following will do that:

Code: Select all

convert 20553-Claywell-S.jpg -density 300x300 -units pixelsperinch -background none -rotate -5 -geometry 194x233 wfTran.gif

convert -size 225x256 xc:white wfTran.gif -gravity Center -composite wfWhite.gif
(Personally, I would use PNG, to retain the anti-aliased edges.)

I'll try that convert command and see what comes out of it. I've tried setting the BG to green1 and flood filling it transparent to combat the white issue, however, I end up with green artifacts, mostly due to the gif requirement. PNG is not a supported format for transparency in IE, and the developers are demanding gif... DOH!

Re: I've had no luck in the Perl Magic Forum.... Any though

Posted: 2010-02-09T14:31:05-07:00
by mrshake
FYI - I've got this resolved for now... I think.. I shortened the code quite a bit.