Page 1 of 1

Blurring with Transparent Background

Posted: 2009-02-08T18:37:36-07:00
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);


Re: Blurring with Transparent Background

Posted: 2009-02-08T18:53:37-07:00
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?

Re: Blurring with Transparent Background

Posted: 2009-02-08T19:06:00-07:00
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

Re: Blurring with Transparent Background

Posted: 2009-02-08T19:40:47-07:00
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.

Re: Blurring with Transparent Background

Posted: 2009-02-09T17:14:40-07:00
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

Re: Blurring with Transparent Background

Posted: 2009-02-10T03:11:55-07:00
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.

Re: Blurring with Transparent Background

Posted: 2009-02-10T14:35:45-07:00
by mkoppanen
The diff I pasted was actually wrong but that is now fixed in CVS

Re: Blurring with Transparent Background

Posted: 2009-04-17T00:34:37-07:00
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?

Re: Blurring with Transparent Background

Posted: 2009-06-05T22:26:18-07:00
by pooco
bump, can't solve.

Re: Blurring with Transparent Background

Posted: 2009-06-23T13:45:01-07:00
by mkoppanen
Seems to work with blurImage but not with gaussian. Wizards?