Page 1 of 1

converting php string to shell command

Posted: 2007-08-31T11:14:10-07:00
by erdan
I want to create a photo annotation using the command line convert function

If I go to the command line and enter the code it works

Code: Select all

/usr/bin/convert -fill yellow -pointsize 30 -draw 'text 10,10 "message_here"' /home/domain/public_html/files/image.jpg /home/domain/public_html/files/anno-image.jpg
when I enclose it in a php script as

Code: Select all

$string = "
\/usr\/bin\/convert -fill yellow -pointsize 30 -draw 'text 10,10 \"message_here\"' \/home\/domain\/public_html\/files\/image.jpg \/home\/domain\/public_html\/files\/anno-image.jpg"

exec($string);
(when I echo the string, it comes out ok with the escaped characters--- but doesnt process correctly)


It does not work and it is dumping core.98327 files in my html directory?
(with multiple files per operation and varying serial numbers)

Any ideas?
Do I need to enter carriage returns in the shell command
Can this be encoded into the string as escaped characters?
Is exec the proper command -- do I need shell_exec? or system(), or other command?

I am trying to implement this on multiple servers and want to limit the wholes that have to be opened and limit the dangerous php fcns that need to be used...

Re: converting php string to shell command

Posted: 2007-08-31T11:52:38-07:00
by Bonzo
I would write the code like this as you do not need to worry about so many escape characters.

Code: Select all

exec("/usr/bin/convert /home/domain/public_html/files/image.jpg -fill yellow -pointsize 30 -draw 'text 10,10 \"message_here\"' /home/domain/public_html/files/anno-image.jpg");
You can also use relative paths from the code.

Re: converting php string to shell command

Posted: 2007-08-31T13:01:49-07:00
by erdan
Same problems...

I am able to produce the same string, but not get it to execute properly from the php script.

Re: converting php string to shell command

Posted: 2007-08-31T13:55:15-07:00
by ridera
Looks like a paths problem. And make certain the dir has the proper permissions. Try this. See the $report; it'll help you debug.

Code: Select all

exec("/usr/bin/convert /files/image.jpg -fill yellow -pointsize 30 -draw 'text 10,10 \"message_here\"' /files/anno-image.jpg", $report);

print_r($report);


Re: converting php string to shell command

Posted: 2007-08-31T15:12:49-07:00
by erdan
I tried to adjust the paths as indicated and it still does not work...

To make it more confusing, there are some operations that do work. I have a test page that echo's the strings that are sent to the convert application and shows the images that should/are created...

Using this methodology, I am able to resize the images, and create a border... It is just the drawing or more complex operations that are failing.... Not sure why? whether it is syntax, " ' issues, or that these operations require other apps/modules...

I initiall got gs errors because it was not installed. I installed it and pasted these strings directly into a shell window and the conversion went fine... It is failing just when executed by my php scripts and JUST for this last script

Code: Select all

/usr/bin/convert -quality 100 -antialias -resize x320 /home/websites/public_html/files/0708311807_Monsoon.jpg /home/websites/public_html/files/0708311807_Monsoon.jpg  ###WORKS###

/usr/bin/convert -quality 100 -antialias -resize x90 /home/websites/public_html/files/0708311807_Monsoon.jpg /home/websites/public_html/files/thumb/0708311807_Monsoon.jpg ###WORKS###

/usr/bin/convert -mattecolor black -frame 5x5+2+2 /home/websites/public_html/files/0708311807_Monsoon.jpg /home/websites/public_html/files/0708311807_Monsoon.jpg ###WORKS###


report:
Array ( )

/usr/bin/convert -fill yellow -pointsize 30 -draw 'text 10,10 "message_here"' /files/0708311807_Monsoon.jpg /files/anno-0708311807_Monsoon.jpg ###FAILS###

/usr/bin/convert /files/0708311815_Monsoon.jpg -fill yellow -pointsize 30 -draw 'text 10,10 "message_here"' /files/anno-0708311815_Monsoon.jpg ###FAILS###

/usr/bin/convert /home/websites/public_html/files/0708311817_Monsoon.jpg -fill yellow -pointsize 30 -draw 'text 10,10 "message_here"' /home/websites/public_html/files/anno-0708311817_Monsoon.jpg ###FAILS###

###################################
The php script that generates this echoed string is:

$imstring="/usr/bin/convert $from -fill yellow -pointsize 30 -draw 'text 10,35 \"message\"' $to_anno";
exec($imstring, $report);
echo $imstring;

Not sure if it means anything but it is copying over the image, it is just not applying the annotation to it. ie it is loading a exact copy of the initial file as the processed file...

Re: converting php string to shell command

Posted: 2007-08-31T18:47:46-07:00
by erdan
If I am right, this appears to be a server permission issue.

I am running the php command from a domain account of a server that I manage.
I enabled phpsuexec and suexec to prevent stuff running as nobody.

When I run the shell commands, I am logged in as root and everything works fine
When I check the owner of the successful php executed commands, the owner is the domain user (websites)

I did check the perms of /usr/bin/convert and /usr/bin/gs and they are identical.

I am in way over my head....

if anyone familiar with these issues, ie which applications (gs, etc) are being called in these draw/annotation scripts that are not called when just resizing using convert... How do I reset permissions so the domain user can perform needed operations using convert.... I would love some help...

thanks
dan

Re: converting php string to shell command

Posted: 2007-09-05T19:41:35-07:00
by anthony
Add 2>&1 to the command so that the error channel is redirected to stdout.
You can then see the error that the command is reporting!!!!

Re: converting php string to shell command

Posted: 2007-09-06T10:25:23-07:00
by Bonzo
Expanding on Anthonys post try this and see what the output is.

Code: Select all

exec("/usr/bin/convert $from -fill yellow -pointsize 30 -draw 'text 10,35 \"message\"' $to_anno 2>&1", $array); 
print_r($array);