polaroidImage and transparent formats

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
tk1
Posts: 17
Joined: 2011-07-27T05:42:54-07:00
Authentication code: 8675308
Location: Poland

polaroidImage and transparent formats

Post by tk1 »

Hi!

I'm writing PHP functions with Imagick to make some effects on the webpages. I use polaroidImage function but when non transparent images are posted I see black border. I would like to have transparent background.

How can I detect if image supports transparency and then save as f.e. PNG ?
cheers
tk1
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: polaroidImage and transparent formats

Post by snibgo »

tk1 wrote:... but when non transparent images are posted ...
I don't think that is what you mean.

It might help if you posted your code and sample inputs/outputs.

To ensure an image has no transparency, "-alpha off" is the command-line option.
snibgo's IM pages: im.snibgo.com
tk1
Posts: 17
Joined: 2011-07-27T05:42:54-07:00
Authentication code: 8675308
Location: Poland

Re: polaroidImage and transparent formats

Post by tk1 »

[code]
try {
$newIm = new \Imagick();
$newIm->setBackgroundColor(new \ImagickPixel('transparent'));
$newIm->readImage($file);

$geo = $newIm->getImageGeometry();
$newIm->polaroidImage(new \ImagickDraw(), $value); // IM >= 6.3.2
$newIm->resizeImage($geo['width'], $geo['height'], $this->gfxConf['windowing_filter'], 1);

$newIm->writeImage($file);
$newIm->destroy();

return TRUE;
}
catch(ImagickException $e) {
[/code]

I would like to add transparency detection and change output image format if prestnt format doesn't support transparency. Now with JPG's I have black background.
cheers
tk1
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: polaroidImage and transparent formats

Post by fmw42 »

JPG does not support transparency. Use PNG or TIFF.
tk1
Posts: 17
Joined: 2011-07-27T05:42:54-07:00
Authentication code: 8675308
Location: Poland

Re: polaroidImage and transparent formats

Post by tk1 »

Yes. Jpeg doesn't support transparency. Users may use my function on various image formats.
This is why I would like to change output image format. But, how to enrich my function in image transparency detection?
I think image extension or format is not enough.
cheers
tk1
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: polaroidImage and transparent formats

Post by fmw42 »

I do not know how you would do this in your API, but see string formats %A and %[channels] to detect transparency at http://www.imagemagick.org/script/escape.php
Post Reply