imageMagick is not working on php exec() - php

echo exec("convert ddd.jpg ddd.png");
return me Invalid Parameter - ddd.png
it is working if I run it on command line, But for php give me this.
also I have checked phpinfo() there is no imageMagick on Enviroment PATH.
But I have added Enviroment PATH by automatical build in.
any ideas?
I feel the problem is PATH is not shown on phpinfo() Enviroment PATH
my server is windows server 2008, using IIS , php5.6
upodate if I run coonvert.exe only
exec('"c:\Program Files\ImageMagick-6.9.3-Q8\convert.exe"',$output,$return)
it will return me same info like in command line.But if I run convert only then give me this.
Array ( [0] => Must specify a file system ) 4
question solved.....
I restarted my server then look phpinfo()
the c:\Program Files\ImageMagick-6.9.3-Q8 is on the list now.....
sorry I am stupid...

Windows has its own convert command,
So you need to use full path to imageMagic's one.

Quick Help for skew images and using tesseract ocr:
shell_exec('"C:\Program Files\ImageMagick-7.0.8-Q16\convert.exe" C:\inetpub\wwwroot\custom\ocr\js\zzz.jpg -quality 100 -resize 1024x768 C:\inetpub\wwwroot\custom\ocr\js\mynew.png');
shell_exec('"C:\Program Files\ImageMagick-7.0.8-Q16\convert.exe" C:\inetpub\wwwroot\custom\ocr\js\mynew.png -gravity North -chop 0x550 C:\inetpub\wwwroot\custom\ocr\js\s3.png');
shell_exec('"C:\Program Files\ImageMagick-7.0.8-Q16\convert.exe" C:\inetpub\wwwroot\custom\ocr\js\s3.png -deskew 6% C:\inetpub\wwwroot\custom\ocr\js\s4.png');
shell_exec('"C:\Program Files\Tesseract-OCR\tesseract" "C:\inetpub\wwwroot\custom\ocr\js\s4.png" output_datas --psm 6');

Related

Imagemagick : PHP Script giving 'import: unable to open X server'

I am trying to capture my current window using ImageMagick using PHP script, but got error as response. I did searched for it in stackoverflow, but none of them solved my issue. I did installed imagemagick in my machine Ubuntu 14.04 . Following command gives me proper output.
import -window root screenshot.jpg
I have this in image.php
<?php
exec( "/usr/bin/convert rose: -resize 200x200 output.jpg");
exec( "/usr/bin/import -window root screenshot.jpg");
?>
<img src="output.jpg"/>
I have executed this from terminal
php image.php
And i got desired response(screen got captured and a file got created name screenshot.jpg)
Then i tried to access this above php script using my browser, The convert command works fine but for import comamnd nothing happens, i tried checking my apache log and it gives me following error
import: unable to open X server `' # error/import.c/ImportImageCommand/368.
What am i missing here?
Is it a permission issue?
If you are trying to do this only for tests and/or studies:
1 - Check if the apache user can run the commands
/usr/bin/convert rose: -resize 200x200 output.jpg
/usr/bin/import -window root screenshot.jpg
2 - Check if you have X11 installed and configured, set the display env var. DISPLAY=:0 for example
3 - Adjust the command import
/usr/bin/import -window root
to /usr/bin/import -window apache_user
or /usr/bin/import -window your_user
If you are trying to create a website that will be accessed by multiple clients with different operational systems, your code will not work. You will need to do that using only PHP code because, obviously, the windows machine does not have the convert and the import commands.
You can read here some how to's

ImageMagik convert command on Windows 2008

I am trying to execute a simple ImageMagick convert command from a php script, i can convert the same files and achieve the results via command prompt but in php i am unable to execute the same command by any means , the code is :
exec('convert -density 350 '.__DIR__ . DIRECTORY_SEPARATOR .'test.pdf '. __DIR__ . DIRECTORY_SEPARATOR . 'image.png');
and this error is thrown by php
convert.exe: no decode delegate for this image format
'C:\XAMPP\htdocs\test.pdf' # error/constitute.c/ReadImage/532.
convert.exe: missing an image filename 'C:\XAMPP\htdocs\image.png' #
error/convert.c/ConvertImageCommand/3016.
With same configuration on a Windows 7 x64 i can execute and achieve the result, but on windows 2008 R2 i am unable, what could be the cause for this?
Ok, so solution was quite simple and straightforward, you just need to make sure that the permissions on C:\Windows\Temp and to that of Imagick "CONVERT.EXE" folder are set to "EVERYONE -> ALL" So , group everyone has permissions of doing what soever with the convert and Temp folder.
Hope it helps.

Run pdftk by php on linux centos

I would like to run pdftk on my webserver. It's a Linux Centos with PHP 5.3.2.
When I connect it by commande line I do
pdftk --version
It's OK
pdftk A=p1-9.pdf cat A1 output p1.pdf
It's OK.
Now, I do this by php :
exec(pdftk A=p1-9.pdf cat A1 output p1.pdf)
It isn't OK. Why?? I search about the link of file, but it looks OK.
This doesn't work too :
exec(pdftk --version)
I install pdftk with this How do I install Pdftk on my server?
So what's wrong??
Thank for your help!
I've run into this issue before. Assuming that you're wrapping your commands string in quotes (as gioele noted), the issue may be that you need to set your path when running the system command. Try this:
$command = "pdftk A=p1-9.pdf cat A1 output p1.pdf";
system("PATH=\$PATH:/usr/bin/ && $command",$response);
if ($response===FALSE){
//there was an error, handle it
}
(I've added a little response handling there as well). If that doesn't work, check to see what path you should use (it will depend on where you installed PDFTK).
I believe you can also get the same result by using putenv("PATH=" .[your path]); and I've used system() here, but exec() should be affected in the same way

How can I use ffmpeg with PHP's exec( ) command?

I'm running Max OS 10.7, MAMP (PHP 5.3.6), with FFMPEG installed. I want to convert videos from one format to another. The following entered into Terminal works fine:
ffmpeg -i /path/video.wmv /path/video.flv
The file video.wmv is converted to video.flv. Great! Now, this PHP line DOESN'T work:
exec('ffmpeg -i /path/video.wmv /path/video.flv');
Why? I've spent many hours reading up on this and I still can't figure out what is wrong. I have read the other discussions on this topic and there is no clear answer. Any help would be greatly appreciated! (PHP safe_mode is off).
I would double check that the path to ffmpeg is correct. Also, take a look at the output to see if has anything useful, like this:
exec("/usr/bin/ffmpeg -i $srcFile $destFile 2>&1", $output);
var_dump($output);

ImageMagick works by command line but doesn't work from PHP

I use Windows 7 and Apache server on my personal computer to develop web applications. Today I installed the ImageMagick for Windows and when I try do an operation from command line it works, for example:
convert -scale "300x300>" -quality 80 -strip "d:/www/test.jpg" "d:/www/test2.jpg"
But the same command run from PHP doesn't work:
exec('convert -scale "300x300>" -quality 80 -strip "d:/www/test.jpg" "d:/www/test2.jpg"');
Why? Please help me!
What do you mean by "doesn't work"? Any errors?
I successfully use imagemagick on Windows 7 from PHP, by using the absolute path to imagemagick.
exec('C:\imagemagick\convert -scale "300x300>" -quality 80 -strip "d:/www/test.jpg" "d:/www/test2.jpg"');
use below form for paths
d:\www\test.jpg
d:\www\test2.jpg

Categories