Page 1 of 1
polaroidImage and transparent formats
Posted: 2016-04-21T13:12:21-07:00
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 ?
Re: polaroidImage and transparent formats
Posted: 2016-04-21T13:40:17-07:00
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.
Re: polaroidImage and transparent formats
Posted: 2016-04-22T23:15:57-07:00
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.
Re: polaroidImage and transparent formats
Posted: 2016-04-23T00:01:16-07:00
by fmw42
JPG does not support transparency. Use PNG or TIFF.
Re: polaroidImage and transparent formats
Posted: 2016-04-23T11:07:37-07:00
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.
Re: polaroidImage and transparent formats
Posted: 2016-04-23T12:28:10-07:00
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