简体   繁体   中英

Imagemagick convert command not working through PHP

I am trying to run imagemagic command throught PHP, this command working perfectly from command prompt but not from PHP, what can be the issue. Other simple convert commands are working through PHP

convert -size 101x111 -background none -fill '#fcfcfc' -pointsize 15 label:'Whitesdd' -trim \/var/www/html/clients/kahuna.in/uploads/kukui_single_nut_image/14925222350_color.png +swap -gravity center -composite \/var/www/html/clients/kahuna.in/uploads/kukui_single_nut_image/14925222350.png

Through PHP

system("convert -size 101x111 -background none -fill '#fcfcfc' -pointsize 15 label:'Whitesdd' -trim \/var/www/html/14925222350_color.png +swap -gravity center -composite \/var/www/html/14925222350.png 2>&1", $var);

output os
convert: not authorized `Whitesdd' @ error/constitute.c/ReadImage/454. convert: no such image `/var/www/html/14925222350_color.png' @ error/mogrify.c/MogrifyImageList/8221. convert: no images defined `/var/www/html/14925222350.png' @ error/convert.c/ConvertImageCommand/3046.

Not sure exactly what your result is supposed to look like but this should work without creating any errors:

You only need a relative path to the image which may have been the problem Writing the code like this means you can echo the command when using variable that will help fault find. It also splits the code up into readable chunks. You could probably use parenthases to help control the code.

Out of interest I do not use the imagemagick API ( imagick ) as I find it does not support a lot of the options and you need to write more code.

<?php
$cmd = "-size 101x111 -background none -fill '#fcfcfc' ".
" -pointsize 15 label:'Whitesdd' -trim input.png +swap ".
"-gravity center -composite 14925222350.png ";

exec("convert $cmd 14925222350.png ");
?>

Two possible issues.

First, you have your output image, 14925222350.png, specified twice in your code, first in the cmd and second in the php convert.

Second, try adding the full path to convert.

Try this to see what error messages you get:

<?php
exec("path2/convert $cmd 2>&1",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

Where you can try without the path2/ or provide your path to convert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM