Blurring with Transparent Background

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
dismissedasdrone

Blurring with Transparent Background

Post by dismissedasdrone »

I have an image that I am creating that has a transparent background with another image loaded and centered over it. When I blur the image the blurring stops at the edge of the original image and does not mix with the transparent background. However, when I change the transparent background to 'white' the blending extends into the background.

Is there any way to get the blending to extend into the transparent background - or at least another method to achieve this visual result?

Here is a sample of code:

Code: Select all


// Does Not Blur Into Background
$new = new Imagick();
$new->newImage($width,$height,'transparent','png');
$new->compositeImage($original_image, Imagick::COMPOSITE_DEFAULT, $buffer_w, $buffer_h);
$new->motionBlurImage($radius,$sigma,180);
$new->motionBlurImage($radius,$sigma,360);

// Does Blur Into Background
$new = new Imagick();
$new->newImage($width,$height,'transparent','png');
$new->compositeImage($original_image, Imagick::COMPOSITE_DEFAULT, $buffer_w, $buffer_h);
$new->motionBlurImage($radius,$sigma,180);
$new->motionBlurImage($radius,$sigma,360);

dismissedasdrone

Re: Blurring with Transparent Background

Post by dismissedasdrone »

Looking here: http://www.imagemagick.org/Usage/convolve/#blur [ bottom of the page], it looks like the issue may be with the alpha channel not being considered.

The fix:

Code: Select all

  
convert black_circle.png  -channel RGBA  -blur 0x8  black_blurred_RGBA.png

How would I accomplish this with Imagick?
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Blurring with Transparent Background

Post by el_supremo »

See: http://ca3.php.net/manual/en/function.i ... rimage.php
You would specify imagick::CHANNEL_ALL for the optional channel argument.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
dismissedasdrone

Re: Blurring with Transparent Background

Post by dismissedasdrone »

el_supremo wrote:See: http://ca3.php.net/manual/en/function.i ... rimage.php
You would specify imagick::CHANNEL_ALL for the optional channel argument.

Pete
The effect that I am going for requires the motionblurimage function, which does not appear to have a channel argument.
Ref: http://ca3.php.net/manual/en/function.i ... rimage.php

Currently, I'm just using Imagick::writeImage at that point to store the image to a file and then running ImageMagick via shell to achieve the effect, but I'd prefer a solution that didn't require running any external process.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Blurring with Transparent Background

Post by mkoppanen »

Hello,

I added the optional channel argument. Use the CVS version if you need it:
http://cvs.php.net/viewvc.cgi/pecl/imag ... 22&r2=1.23

The channel argument is available if Imagick is compiled against ImageMagick version > 6.4.3
Mikko Koppanen
My blog: http://valokuva.org
dismissedasdrone

Re: Blurring with Transparent Background

Post by dismissedasdrone »

mkoppanen wrote:Hello,

I added the optional channel argument. Use the CVS version if you need it:
http://cvs.php.net/viewvc.cgi/pecl/imag ... 22&r2=1.23

The channel argument is available if Imagick is compiled against ImageMagick version > 6.4.3
Many thanks! I will give it a try.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Blurring with Transparent Background

Post by mkoppanen »

The diff I pasted was actually wrong but that is now fixed in CVS
Mikko Koppanen
My blog: http://valokuva.org
pooco

Re: Blurring with Transparent Background

Post by pooco »

Did this work for you?

I start with something very similar:

$canvas->newImage($width,$height,'transparent','png');

drop some text on the canvas:

$canvas->annotation(..)

try to blur:

$canvas->gaussianBlurImage(0,2,imagick::CHANNEL_ALL);

and save:

$canvas->writeImage(..)

but the transparency is never with an alpha channel. the only time blur looks proper is in images with a solid background..

anyone?
pooco

Re: Blurring with Transparent Background

Post by pooco »

bump, can't solve.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Blurring with Transparent Background

Post by mkoppanen »

Seems to work with blurImage but not with gaussian. Wizards?
Mikko Koppanen
My blog: http://valokuva.org
Post Reply