views:

114

answers:

4

Hello everybody,

I want to convert a pdf file to an image with PHP, but i can't get the command worked. PHP returns a 4. I don't have any kind of idea what that can be.

I am using the next code:

$tmp = system("convert -version", $value); 
var_dump($value);

Someone an idea?

+1  A: 

It looks like the -version flag is telling the convert software (looks like imagemagick) to respond with the major version number of that software. It looks like it is working correctly. You probably need to pass it the right flags to operate properly. I suggest reading the documentation to see what flags are required to convert PDFs.

John Conde
i think not. because if I use convert w11y2010.pdf test.png as command it gives also int(4)...
Tom
@tomk94 int(4) is different from `4` - that is most likely a system return code.
Pekka
What does a `var_dump($temp)` say? That should be more enlightening.
Pekka
sorry for all misunderderstanding. var_dump($value) returns int(4) and var_dump($tmp) returns string(0) ''
Tom
+1  A: 

try using some of the other system functions in PHP to get more detailed output.

exec("convert -version", $output, $value);
print_r($output);

The exec function above will give you all the output from the command in the $output parameter, as an array.

The return status (which will be held in the $value parameter in the exec call above or the system call in your original code) gives you the return value of the executed shell command.

In general, this will be zero for success, with non-zero integer return values indicating different kinds of error. So it appears there's something wrong with the command as you have it (possibly -version is not recognised: often you need a double hyphen before long-hand command-line options).

Incidentally, you may also find that the passthru function is more suited to your needs. If your convert program generates binary image data corresponding to the converted PDF, you can use passthru to send that image data directly to the browser (after setting the appropriate headers of course)

A: 

try

  exec("convert -version 2>&1", $out, $ret);
  print_r($out);

it should tell you what's wrong

stereofrog
thank you, now i get: Array ( [0] => Ongeldige stationsspecificatie. ) in english: 'invalid drive specification'. On google the tell about that imageshack is'nt installed, but it is because convert -version in cmd works!
Tom
looks like it invokes Windows standard tool "convert" instead of Imagick program. Try providing the full path like `exec("\\path\\to\\imagick\\convert")`
stereofrog
@stereofrog thank you!
Tom
A: 

err... aren't you vardumping the wrong result? (I would var dump $tmp, not $value.)

I think the code should read:

$tmp = system("convert -version", $value); 
var_dump($tmp);
Bingy