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 ?
polaroidImage and transparent formats
polaroidImage and transparent formats
cheers
tk1
tk1
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: polaroidImage and transparent formats
I don't think that is what you mean.tk1 wrote:... but when non transparent images are posted ...
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
Re: polaroidImage and transparent formats
[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.
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
tk1
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: polaroidImage and transparent formats
JPG does not support transparency. Use PNG or TIFF.
Re: polaroidImage and transparent formats
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.
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
tk1
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: polaroidImage and transparent formats
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