0

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.

Joe Workman
  • 341
  • 1
  • 16
  • If they allow you to execute perl or python or just basic binaries on your user account, you could call them from php. – James McDonnell Nov 26 '12 at 20:31
  • They don't allow me to run `exec` at all. That is why I would like to accomplish this all using the ImageMagick PHP module. – Joe Workman Nov 26 '12 at 20:51

2 Answers2

1

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?

Bonzo
  • 5,169
  • 1
  • 19
  • 27
0

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);
Joe Workman
  • 341
  • 1
  • 16