Page 1 of 1

how to add opacity to image?

Posted: 2008-06-28T00:52:06-07:00
by hotzenplotz
hello,
how can I add opacity to an image? It's important to preserve the transparency in PNG's and GIF's.x
The following seems to do nothing:

$image=new Imagick($file);
$image->setImageType(Imagick::IMGTYPE_TRUECOLORMATTE);
$image->evaluateImage(Imagick::EVALUATE_SUBTRACT, $opacity,
Imagick::CHANNEL_OPACITY);
$image->writeImage($file_new);

and this seems to add opacity, but when opening the picture, I can see only a black square

$image=new Imagick($file);
$image->setImageOpacity(round($opacity/100,1));
$image->writeImage($file_new);

what can I do?

nico

Re: how to add opacity to image?

Posted: 2008-06-29T14:51:53-07:00
by mkoppanen
Hi,

can i see the image youre processing?

Re: how to add opacity to image?

Posted: 2008-07-01T13:19:05-07:00
by hotzenplotz
Hi,

there was a little error in my description. Right is, that the first statement does nothing and the second adds opacity to complete image, so I can see the partially transparent square on a colored background. For testing I'm using the "Silk Icons" from http://www.famfamfam.com/lab/icons/silk/ (ie female.png).

Nico

SOLVED Re: how to add opacity to image?

Posted: 2008-07-02T13:08:58-07:00
by hotzenplotz
hi,

$image->evaluateImage(Imagick::EVALUATE_MULTIPLY, 0.3,
Imagick::CHANNEL_OPACITY);

works as expected. now I'm still looking for a solution to display animated gif through PHP API in browser...

thanks

Re: how to add opacity to image?

Posted: 2008-07-05T11:24:18-07:00
by mkoppanen
you need to send correct headers and use the getImagesBlob method.

Re: how to add opacity to image?

Posted: 2008-07-05T11:50:39-07:00
by hotzenplotz
mkoppanen wrote:you need to send correct headers and use the getImagesBlob method.
header('Content-type: image/gif'); should be right, but the real problem seems to be the gif handling by imagick, see http://imagemagick.org/discourse-server ... =1&t=11579
whatever I do to load the gif file in imagick, only the first frame is rendered...

$image=file_get_contents("image.gif");
header(...);
echo $image;

works, but simple script

$image=file_get_contents("image.gif");
header(...);
$im=new Imagick();
$im->readImageBlob($image);
echo $im->getImageBlob();

shows first frame... :(

Re: how to add opacity to image?

Posted: 2008-07-08T08:01:30-07:00
by mkoppanen
Can you re-read what I posted? This time with care.

Re: how to add opacity to image?

Posted: 2008-07-08T11:59:06-07:00
by hotzenplotz
I've re-read it for times and noticed, that you wrote getImagesBlob, but when looking into php documentation of imagick, this function call is not documented. alls works perfectly. great thanks.