Picci Picci - 1 year ago 45
PHP Question

ImageMagick unix shell script doesn't work when fired with php shell_exec()

I have to create a transition sequence of images, using Fred's ImageMagick scripts,in particular fx transitions.

In my php code, I resize all the images i got to a standard size, then I rename all those pictures to something like pic000001.jpg, pic000002.jpg, pic000003.jpg and so on (i keep count with $count), then I do:


//for all the pic000001.jpg, pic000002.jpg, pic000003.jpg.... do a transition
//between them

//here I take a picture and the next(IE pic000001 and pic000002)
echo shell_exec("fxtransitions -e swirl -f $frames -d 20 -p 50 $path/pic".str_pad($seq, 6, '0', STR_PAD_LEFT).".jpg $path/pic".str_pad(($seq+1), 6, '0', STR_PAD_LEFT).".jpg $path/fx%06d.jpg");

//here I rename the temporany frames called
//fx000000.jpg to fx000035.jpg for each transition
//to a common index
rename("fx".str_pad($c, 6, '0', STR_PAD_LEFT).".jpg" ,str_pad($frameIndex, 6, '0', STR_PAD_LEFT).".jpg");

Then, I use FFMpeg to combine all frames and make a video.
The problem is that fxtransition states an error:


(which is a message generated by the script for sure), followed by messages like this:

Warning: rename(fx000000.jpg,000000.jpg): No such file or directory in /var/www/html/TEST/APP/generateVideo.php on line 168

because the pictures weren't generated (it reveals that the aloghoritm for numbering the frame is correct, so don't focus on that).

If I open the terminal on the server, with a ssh connection and I run that command, it gives me the same error, unless I use sudo.
If I use sudo on php shell_exec, it won't exec.
shell_exec('whoami') returns apache, and apache is the owner of all the folders and files I involve in those functions.

Some help please?
If you have an alternative to fred's imagemagick's scripts to generate transition frames to generate a video it will also be appreciated.

Answer Source

I encountered this issue when using one of Fred's ImageMagick scripts. The solution is to update the script file (scriptname.sh) using your favorite editor (vim, nano, etc) and set the correct temp directory. See below:

# set directory for temporary files
dir="."    # suggestions are dir="." or dir="/tmp"

In my case the temp directoy was "/tmp"

# set directory for temporary files
dir="/tmp"    # suggestions are dir="." or dir="/tmp"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download