Question

I am moving to a new hosting company that will not allow me to exec a convert command for ImageMagick. So I now have to attempt to do it through straight PHP. I have spent quite a bit of time trying to figure it out and every where that I look, people recommend using the convert command like I am. I would appreciate any help or guidance in writing the following commands in straight PHP.

# Applies overlay $filter_image to the original $image
convert $image ( -clone 0 -alpha off $filter_image -compose SoftLight -composite ) -compose SrcIn -composite $output_image

and

# Apply a blur to an image
convert $image -blur 0x$blur_radius $output_image

UPDATE:

I have figured out the syntax and posted it as an answer.

Was it helpful?

Solution 2

I finally figured it out on my own. Here is the solution in case anyone else runs into this.

Blur an image...

$imagick = new Imagick($image);
$imagick->blurImage(0,$blur_radius);
$imagick->writeImage($output_image);

Add an overlay to an image...

$imagick = new Imagick($image);
$overlay = new Imagick($filter_image);

$imagick->compositeImage($overlay, imagick::COMPOSITE_SOFTLIGHT, 0, 0);
$imagick->writeImage($output_image);

You can easily combine the two methods as well and blur the image and then add a composite overlay to it.

$imagick = new Imagick($image);
$imagick->blurImage(0,$blur_radius);

$overlay = new Imagick($filter_image);
$imagick->compositeImage($overlay, imagick::COMPOSITE_SOFTLIGHT, 0, 0);

$imagick->writeImage($output_image);

OTHER TIPS

Best of luck Joe; I would recomend changing to a host that will let you use exec.

I have some examples of the imagick functions on my site that you may be able to cobble something together with: http://www.rubblewebs.co.uk/imagick/functions/function.php

I have just noticed I posted the Imagemagick code not the Imagick ! This is as you now know the blur code for Imagick:

bool blurImage ( float $radius , float $sigma [, int $channel ] )

<?php  
$im = new Imagick($input); 
$im->blurImage( 0, 3 ); 
$im->writeImage('blurImage.jpg');  
$im->destroy(); 
?> 

Might be worth adding an Imagick tag to your post as that is what you want to use?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top