Cron Job scheduling

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
inferno156

Cron Job scheduling

Post by inferno156 »

I am trying to automate a process by using a Cron job and ImageMagick to adjust a photo at midnight each night.

I am using a php script with the exec commands for imagemagick and if I run the script in a browser it works perfectly. But if I run it through a cron job imagemagick fails to create the image. And I know the cron job is working because the script also sends me an email.

I suspect it has something to do with relative vs. direct paths to the images, but I can't seem to figure it out.

This code works when the script is run manually.

Code: Select all

exec("/usr/bin/convert ./large/test.png -resize 55% ./small/test.png");
This code doesn't seem to work at all. I just grabbed the path from a php error.

Code: Select all

exec("/usr/bin/convert /var/www/vhosts/<domain>/httpdocs/large/test.png -resize 55% /var/www/vhosts/<domain>/httpdocs/small/test.png");
Thanks in advance for any help.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cron Job scheduling

Post by Bonzo »

I have a php cron job that works ok with relative paths - out of interest I just use convert not usr/bin/convert.
If I do get any errors they are reported in the email.

Try using your code like this and see if you get any errors:

Code: Select all

echo "<pre>";
exec("convert ./large/test.png -resize 55% ./small/test.png 2>&1", $array);
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Cron Job scheduling

Post by xpt »

inferno156 wrote:I am trying to automate a process by using a Cron job and ImageMagick to adjust a photo at midnight each night.

I am using a php script with the exec commands for imagemagick . . . .
Since it is only a single "convert" command, would it be better to remove an extra layer by doing it right in shell instead of php? Or you need php to feed in all path, file name things?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cron Job scheduling

Post by Bonzo »

If the poster is on a shared hosting he probably will not have access to shell ?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cron Job scheduling

Post by anthony »

Maybe not an interactive shell, But if php can exec a command, it can exec a shell script!

Actually the PHP exec is itself a shell script!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply