Page 1 of 1

Problem with PNG and alpha channels

Posted: 2009-09-30T05:38:23-07:00
by dileso
Hallo,
I have a strange problem by using imageMagick. Even when I use PHP IMagick i post it here because I think it is more related to ImageMagich then to the Interface.

The Problem:
I do create an Image with a shadow and implement this image into a PDF file by using TCPDF.
When I see the created PNG file it looks like expected. Inside the PDF the shadow becomes just a black area.
So I thought it is TCPDF but other png files work fine.
after I open my created file with photoshop and save "for web and devices" as png24 it also works fine inside the PDF
Does anybody has an idea?

here is my code

Code: Select all

$file2 = '../storage/40/test2.png';
$image = new Imagick();
$image->newImage(144,144,'','PNG24');				
$shadow = $image->clone();
$shadow->setImageBackgroundColor(new ImagickPixel('black')); 
$shadow->shadowImage(50,10,50,50);
$shadow->compositeImage( $image, Imagick::COMPOSITE_OVER, 0, 0 ); 
$image = $shadow;
$image->writeImage($file2);
this is how it looks like: (left side is after saving with PS / left side is from ImageMagick)
Image

I got the same result in the shell by using convert:

Code: Select all

 convert -size 200x200 xc:white \( +clone  -background black  -shadow 70x3+10+10 \) +swap -background none   -layers merge  +repage   test1.png
Thanks for your help
Dirk

Re: Problem with PNG and alpha channels

Posted: 2009-10-01T01:01:52-07:00
by dileso
After long searching and testing I think it is maybe TCPDF.
It maybe has a problem with images with alpha cannels > 8 bit.

Does anybody has an idea how to set the alpha channel to 8 bit?

Thanks
Dirk

solved: Problem with PNG and alpha channels

Posted: 2009-10-01T05:23:44-07:00
by dileso
Hi again,

it's funny to be the only one who writes into this thread :D

to add a line to change the channel depth solves the problem the image looks fine inside the PDF.

Code: Select all

$shadow->setImageChannelDepth(0,8)
http://us2.php.net/manual/en/function.i ... ldepth.php

Doe to there is "no" docs for Imagick I have no idea what the first ($channel) means.
to change it 1, 2 ,3 or 4 has no change to the image.

Anyway it works...

So if anybody has the same problem you know how to solve it and if anybody knows what the 1st parameter is standing for or knows a better documentation bleas post it here.

Re: Problem with PNG and alpha channels

Posted: 2009-10-01T05:50:17-07:00
by magick
You probably want to use setImageDepth(8) rather than setting the channel depth.

Re: Problem with PNG and alpha channels

Posted: 2009-10-01T09:41:27-07:00
by fmw42
there is some Imagick Documentation at http://us2.php.net/imagick

Re: Problem with PNG and alpha channels

Posted: 2009-10-01T10:37:51-07:00
by dileso
@magick:
yes this is working too and I can understand the only one parameter :lol:

@fmw42:
this docs are the same that I had. It's nearly in all functions:
Warning
This function is currently not documented; only its argument list is available.
So you only see the arguments but you never know what they standing for.
only sometimes there are some sample codes.

Thanks Dirk

Re: Problem with PNG and alpha channels

Posted: 2009-10-01T10:54:54-07:00
by magick
Channels are the color components of a pixels, typically red, green, blue, and alpha. iMagick should have tokens for each channel RedChannel, GreenChannel, etc. If not, they are probably using mappings, e.g. 0 = RedChannel. With channels you can operate on one or more channels. For example, suppose you only want to sharpen the red channel of an image, you would use use something like SharpenImageChannel( image, RedChannel ).

Re: Problem with PNG and alpha channels

Posted: 2009-10-05T17:08:14-07:00
by anthony
You could flatten the PNG onto white before saving into the PDF. That way no transparency is actually involved :-)

Re: Problem with PNG and alpha channels

Posted: 2010-01-19T07:07:34-07:00
by silenceseeker
anthony wrote:You could flatten the PNG onto white before saving into the PDF. That way no transparency is actually involved :-)
And how do I do that using ImageMagick?

I am having a similar problem, using "convert -flatten". Its description is posted in this thread. Flattening the PNG onto white using PS or GIMP is what I am currently doing (interactively) but this is not the desired solution. I would like to use ImageMagick's convert (or some other command?) to automate this in a batch file.

Thanks.