Page 1 of 1
How to use php and ImageMagick
Posted: 2017-08-02T05:32:53-07:00
by dt59
Code: Select all
<?php
$input = realpath("image.jpg");
$g = exec("convert $input image.png");
if ($g){
echo "yes";
}else{
echo"is not working";
}
?>
i wrote the above simple code but is returning false, could anyone suggest what could be wrong or the potential cause?
Re: Question
Posted: 2017-08-02T07:22:02-07:00
by Bonzo
This is not a php forum ( Imagick is an external program and so might not return anything to php ) and "Question" is a useless title as you have at least two threads with the same title.
Try basing your code on this example:
Code: Select all
exec("convert input.jpg output.png", $output, $return);
if ($return == "0") { echo '<br>Image generation sucssesful<br>'; }
else { echo '<br>Image generation failed<br>'; }
Re: Question
Posted: 2017-08-02T07:27:47-07:00
by dt59
Bonzo wrote: ↑2017-08-02T07:22:02-07:00
This is not a php forum ( Imagick is an external program and so might not return anything to php ) and "Question" is a useless title as you have at least two threads with the same title.
Try basing your code on this example:
Code: Select all
exec("convert input.jpg output.png", $output, $return);
if ($return == "0") { echo '<br>Image generation sucssesful<br>'; }
else { echo '<br>Image generation failed<br>'; }
noted, i guess you're OK now, so could please help me.
Re: How to use php and ImageMagick
Posted: 2017-08-02T09:39:39-07:00
by fmw42
try
exec("convert logo: logo.gif", $output, $return);
Does that work?
if not, try adding the full path to IM convert in your command
Re: How to use php and ImageMagick
Posted: 2017-08-02T10:40:52-07:00
by dt59
Re: How to use php and ImageMagick
Posted: 2017-08-02T10:42:45-07:00
by dt59
does it mean i have to change all the convert in code to magick? but why
Re: How to use php and ImageMagick
Posted: 2017-08-02T11:43:39-07:00
by Bonzo
Windows has a convert program and that may be part of the reason - to stop confusion.
If you installed legacy programs you can still use convert but obviously it is not working for you. So yes you will need to change all converts to magick on any code using V7.
You could add a $convert = 'magick'; at the start of your programs and use $convert in your code. If you go back to a V6 install you only need to change one variable. Otherwise you could have the convert variable in a separate file and include that file in your programs so only changing it once for your whole site. Alternatly you could check for the imagemagick version at the start of your program and set the variable value from the result.
Re: How to use php and ImageMagick
Posted: 2017-08-02T11:48:22-07:00
by dt59
kk, thanks man. so what if i want to run image magick on the world wide web(live sever)? hw would i install image magick on my c-panel
Re: How to use php and ImageMagick
Posted: 2017-08-02T12:17:40-07:00
by Bonzo
You might not be able to and will need to get your host to do it. Otherwise pick a host that has it installed already - make sure it is a later version.
You can use Imagick which is an Imagemagick/php API ( class ) but that is another can of worms.
Re: How to use php and ImageMagick
Posted: 2017-08-02T14:04:32-07:00
by fmw42
dt59 wrote: ↑2017-08-02T10:42:45-07:00
does it mean i have to change all the convert in code to magick? but why
I do not use Windows, but you should be able to set up a symbolic link to map convert to magick. One of the Windows users would have to help.