Problems with Transparency and image rendering

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

Problems with Transparency and image rendering

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

Re: Problems with Transparency and image rendering

Post by mrshake »

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";}
Post Reply