Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imagemagick exec and convert

I recently started using imagemagick with php and I'm relatively new with both of these, IM and PHP. So, I'm here to ask for some help/suggestion(s).

First

If lets say a user uploads a gif or a png image on my site and I want it converted to jpg, is there any command like for example.$image->convert($file,'.jpg) or the convert command is accesible only thru exec() ? like for example exec(convert picture.png to picture.jpg)

Second

What if for again, the user uploads gif/png on the site and I resize the image to a specified width/height and write the image, with the writeImage function of IM like this: $image->writeImage(basename.$ext) where $ext = jpg. Will this work properly,is this a good practice? I assume this will only rename it but still, I don't see a problem in this... o.O

Oh sorry one more question, I'm not very familiar with exec, is it better using imagemagick using exec(), does it improve speed, load etc?

like image 445
inrob Avatar asked Jul 17 '26 10:07

inrob


2 Answers

I can't answer your questions directly but thought I point you to a few resources:

Regarding which is better, exec or the PHP extension, I asked this same question a few months ago:

Should I use a PHP extension for ImageMagick or just use PHP's Exec() function to run the terminal commands?

For all Image Magick PHP functions you should look up the official guide:

http://www.php.net/manual/en/book.imagick.php

I switched from Image Magick to Graphics Magick as I heard it has better performance. It is a fork of Image Magick with an emphasis on performance. Large sites like Flickr and Etsy use it:

http://www.graphicsmagick.org/

This guide got me started:

http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/

And they have their own manual on php.net:

http://php.net/manual/en/book.gmagick.php (most of the commands are identical to Image Magick's)

I prefer using exec() as it is supported a lot better than Imagick ( the example code you posted ), easier to use and supports all the operators ( depending on your version ) which again Imagick does not. Some of the Imagick code works differntly in the different versions; there are a lot more Imagick examples around than there were a couple of years ago when I first started looking at it.

Saying that Imagick can be faster and is/can be? built into php although some people have trouble installing it.

I belive that this site http://valokuva.org/?cat=1 belongs to a Imagick developer and has lots of examples.

My site www.rubblewebs.co.uk/imagemagick has lots of examples of php with exec( )

As to your other two questions yes you can change the file type with Imagick and I am not sure about basename.$ext - why not try it? As long as basename does not have an extension it may work but you might need to include basename.$ext in quotes.

As to speed it dpends sometimes GD is faster other times Imagick or Imagemagick. You can always do some tests. I did some a year or so ago and you can try the code on your server. http://www.rubblewebs.co.uk/imagemagick/speed/Speed_tests_1.pdf

like image 34
Bonzo Avatar answered Jul 19 '26 01:07

Bonzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!