command-line tool identify with popen in php cause problems

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
toxicbrain

command-line tool identify with popen in php cause problems

Post by toxicbrain »

hello,

i hope i can describe my problem. i use the command-line tool identify to get information about some pdf-files. i use the following php-code:

$handle = popen("identify some_file.pdf", "r");
$read = fread($handle, 2048);
pclose($handle);

as a result i only get an error like Error /undefined. and yes, the file exists. but if i a try this command on a shell command line, i get all the information. everything is fine. did i missed something? sorry for my bad english and thanks for your help.
txb

installed versions:
- ImageMagick 6.4.5 2008-11-13 Q16
- php Version 5.2.6
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: command-line tool identify with popen in php cause problems

Post by magick »

A PHP or shell environment may be very different from your command line environment. Try using absolute paths. Instead of identify, try /usr/local/bin/identify. Edit delegates.xml and change "gs" to "/usr/local/bin/gs".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: command-line tool identify with popen in php cause problems

Post by fmw42 »

Not sure if this is relevant to your API, but you may need to add 2>&1 to your command in your API. see something similar to what is show in viewtopic.php?f=1&t=13725 for PHP
toxicbrain

Re: command-line tool identify with popen in php cause problems

Post by toxicbrain »

fmw42 wrote:Not sure if this is relevant to your API, but you may need to add 2>&1 to your command in your API. see something similar to what is show in viewtopic.php?f=1&t=13725 for PHP
yes, i already tried this. but it's cause the same error. anyway for your answer, thanks.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: command-line tool identify with popen in php cause problems

Post by Bonzo »

Tried it on my XAMPP server ( php 5.2.9 ) and it works OK and so there must be something wrong with your setup - no idea what it could be though !
As magic says its probably something to do with paths

Code: Select all

<?php
$handle = popen("identify 310509.pdf", "r");
$read = fread($handle, 2048);
pclose($handle);
echo $read;
?>
// Output
310509.pdf PDF 595x842 595x842+0+0 16-bit DirectClass 1.433mb
toxicbrain

Re: command-line tool identify with popen in php cause problems

Post by toxicbrain »

magick wrote:A PHP or shell environment may be very different from your command line environment. Try using absolute paths. Instead of identify, try /usr/local/bin/identify. Edit delegates.xml and change "gs" to "/usr/local/bin/gs".
thats it! now it works perfectly. thanks a lot.
Post Reply