I can't convert with ImageMagick

I'm using ImageMagick to convert a PDF file.

I use this PHP snippet:

$cadena = "/usr/local/bin/convert -density 100 -colorspace rgb ".$name_path." ".$images_path."/convert.png";
shell_exec($cadena); 

where $name_path is the PDF file directory and $images_path is the images directory.

This code in console (CentOS) works perfectly. But when I try to use shell_exec() function in PHP it throws this error:

***warning: considering '00000000 xxxxx n' as free entry.
*** this file had erros thah were repaired  or ignored.

The permissions in file and folders are 777. I don't know why. Can somebody help me?

Upvotes: 2

Views: 276

Answers (1)

Kurt Pfeifle
Kurt Pfeifle

Reputation: 90203

First of all, two observations:

  1. The message you see is not from ImageMagick, it is from Ghostscript.
  2. The message is not an error message, but merely a warning.

So it may well be that your conversion did work and you'll have the desired output in $image_path. Did you check?

Then, three more points:

  1. ImageMagick does not and can not process input PDF itself. It employs Ghostscript as its delegate to convert PDF to an image format first, which is then taken over by ImageMagick for further processing.
  2. It is not necessarily the case that the Ghostscript version you executed in the CentOS console is the same as the one which is executed by your PHP shell_exec. You should check that for both instances. The console command to do this is gs -version. If you have different versions, this would explain why you do see the warning message in one instance, but not in the other.
  3. You could add -verbose to your commands (shell_exec as well as in console) to see which instance of Ghostscript the IM convert command invokes "behind your back"....

Upvotes: 1

Related Questions