Imagemagick exec and convert
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
inrob
Updated on June 04, 2022Comments
-
inrob almost 2 years
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 thruexec()
? like for exampleexec(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.OOh sorry one more question, I'm not very familiar with exec, is it better using imagemagick using
exec()
, does it improve speed, load etc?