ImageMagik convert command on Windows 2008 - php

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.

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

imageMagick is not working on php exec()

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');

CentOS Linux console command versus PHP exec(command)

I have a C program that I wrote called convert3to5, originally written for CentOS / Fedora 32bit system in early 2010. I am moving it to new CentOS 6.x 64bit system host.
From a CentOS Putty console I can run the convert3to5 command just fine; here is a sample of it running from my console:
[root#cloud convert3to5]# ls
CircleStar convert3to5 Convert3To5.txt test.tif
[root#cloud convert3to5]# ./convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
TIFFReadDirectory: Warning, /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif: wrong data type 7 for "RichTIFFIPTC"; tag ignored. Image has an undefined fillorder - using default: MSB2LSB
The above is a normal completion of convert3to5 and I get a SV-DIS160217B.bmp that is placed in /var/www/webadmin/data/www/mydomain.com/uploads/ So running it from console works fine.
Question - I am attempting to run the same exact command from PHP using the exec(command, output, return) command as follows:
chdir($sv_path.$c3to5_path); //change our working directory to "/convert3to5" directory
$command = "./convert3to5 $targetFile 2>&1";
$result = exec($command, $output, $return);
// the output of the above command - is a .bmp file it will be placed in the same path as the input .tif file
I get the following $result:
ERROR: Unable to convert
/var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif to 5
color BMP file: Open file Error: Tiff_3_to_BMP_5_.lut!
My convert3to5 does need to open Tiff_3_to_BMP_5_.lut
Why does it find Tiff_3_to_BMP_5_.lut when I run convert3to5 from a console prompt but not from PHP exec(...) in both cases my pwd shows that I am in
[root#cloud convert3to5]# pwd
/var/www/webadmin/data/www/mydomain.com/myView/convert3to5
I have also verified pwd is correct from my PHP script after the
chdir($sv_path.$c3to5_path);
Tiff_3_to_BMP_5_.lut is in CircleStar directory - the path to CircleStar is /var/www/webadmin/data/www/mydomain.com/myView/convert3to5/CircleStar
Summary: ./convert3to5 works while PHP exec('convert3to5 ..) does not appear to work.
Can anyone suggest the difference and how to fix and/or debug?
Thanks
You're running the console from the convert3to5 directory, and I suspect your old C program used a relative path to the .lut file, possible relative to the .tif?
What if in the console example you did
cd ../..
./path/to/convert3to5/convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
Might be related to $targetFile. Print that and see if it's the full path.
Finally, run
/full/path/to/convert3to5 fullTargetPath
If that works, then as a workaround, if you just do exec('/full/path/to/convert3to5 $fullTargetPath, ..) it should behave like the console.
Per my above comment to wonton:
From the console I was running as root (so fully privileged). I supposed my PHP script will run as the "apache" user on the server?
Here was the problem I believe: I looked at the CircleStar directory privileges where the Tiff_3_to_BMP_5_.lut file exists. CircleStar had rw-r--r-- (0644) when running as root from console this allowed my convert3to5 program to find and open Tiff_3_to_BMP_5_.lut file just fine. However not the PHP exec(...) once I changed the privilege on CircleStar to rwxr-xr-x (0755) PHP exec(...) ran fine!
So ultimately it was a permission issue.

php libreoffice shell_exec not working

I am trying to convert .docx file to .html using php shell_exec in CentOS 6.5
My php code:
$command = "libreoffice --headless -convert-to html resume.docx 2>&1";
$result = shell_exec($command);
echo $result;
When I run the index.php at http://localhost/converter/ it gives me:
javaldx: Could not find a Java Runtime Environment! Warning: failed to read path from javaldx /usr/lib64/libreoffice/program/soffice.bin X11 error: Can't open display: Set DISPLAY environment variable, use -display option or check permissions of your X-Server (See "man X" resp. "man xhost" for details)`
while in terminal it is working perfectly:
cd /var/www/html/converter/
libreoffice --healdess -convert-to html resume.docx
here it creates resume.html in my /var/www/html/converter/.
Hi i have the same problem, i want to convert PDF's from DOCS created with PHP, i'm using OpenSuse 12.3 with LibreOffice, tried many things, finally i detect that the error is in folder:
1.- First check that you don't have disabled shell_exec in php.ini, and open_basedir don't restrict your access folders.
2.- Run the command as a simple user in shell (terminal)
export HOME=/tmp && soffice --headless --convert-to pdf --outdir /srv/www/htdocs/ /srv/www/htdocs/Creecimientos/sic/app/webroot/usuarios/2/8_Pagare_CreePersonas.docx
3.- If it works, you only have to put the correct folders in your code, when i run this code in PHP, it show me a blank page, so i check the access_log of apache for any hint:
[Java framework] Error in function createSettingsDocument (elements.cxx).
javaldx failed!
Warning: failed to read path from javaldx
terminate called after throwing an instance of 'com::sun::star::uno::RuntimeException'
Note: my error was in using export HOME=/tmp, i checked that the folder in root system has 777 for tmp, but the problem was that apache don't acces to it, maybe search for a relative folder of the script, but after test many things i only put a folder with permissons for wwwrun HOME=/srv/www/htdocs/folder_with_777
This is my final code, that works..
<?php
function word2pdf()
{
echo "Procesando";
$result = shell_exec('export HOME=/srv/www/htdocs/Creecimientos/sic/ && soffice --headless --convert-to pdf --outdir /srv/www/htdocs/Creecimientos/sic/ /srv/www/htdocs/Creecimientos/sic/app/webroot/usuarios/2/8_Pagare_CreePersonas.docx');
echo $result;
}
word2pdf();
?>
In fact, it prints: convert srv/www/htdocs/Creecimientos/sic/app/webroot/usuarios/2/8_Pagare_CreePersonas.docx -> /srv/www/htdocs/Creecimientos/sic//8_Pagare_CreePersonas.pdf using writer_pdf_Export, after succes.
I made other changes before in desesperate mode, but none of them solved the problem, tried to change owner to soffice wich found it witch $ ls -l $(which libreoffice), tried with 777, etc..
/* This command will work on centos 6 /7 with installation of libreoffice headless package */
First install package on centos as :
yum install libreoffice-headless
/* following code work to extract text format from */
<?php
$result = exec("export HOME=/tmp/ && /usr/bin/libreoffice --headless --convert-to txt:Text --outdir /tmp filePath");
var_dump($result);
?>
Most likely the user that LibreOffice is ran as, does not have a writeable home directory so LibreOffice fails to create it's config directory and then it cannot create it's config files and then fails to load Java, because it cannot write the default config. A bit silly I know.
Try adding this parameter: -env:UserInstallation=file:///tmp/whateverhere
I don't have enough reputation to comment on TD_Nijboer's answer, but the answer to his specific problem appears to be that soffice needs to be able to read & write config information somewhere. The first place it tries to do this is the libreoffice directory in ~/.config ('~' means "the current user's home directory").
In Debian, by default, the www-data user has the home directory /var/www, and does not have write permission there.
If you make sure it has permission to either create ~/.config itself, or libreoffice within an existing ~/.config, I expect it will work.
2 things, 1st the command is soffice --headless,
2nd i have an similar javaldx error and it has to do with permission.
when executing as root it works fine, but php executes as www-data.
if anybody knows a good way to execute libreoffice from php please let me know.
as i'm getting an error code 77 saying:
[Java framework] Error in function createSettingsDocument (elements.cxx).
javaldx failed!
Warning: failed to read path from javaldx

FFmpeg - PHP Error Code 127

I am trying to execute FFmpeg from php. I have installed FFmpeg-php, and the extension is in the modules directory and it shows up in phpinfo. FFmpeg is working fine as I can run the command in a terminal and it outputs the video. However, when I try and run the command from php using the following script:
exec(ffmpeg -i input.avi output.avi);
But I get a '127' error code.
The extension is loaded in using:
$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
// Locate Extension
define('FFMPEG_LIBRARY', '/usr/local/bin/ffmpeg');
// Load Extension
if (!extension_loaded($extension))
echo dl($extension_soname) or die("Can't load extension $extension_fullname\n");
I have also tried defining the aboslute extension location in the command:
exec(/usr/local/bin/ffmpeg-i input.avi output.avi);
Again, this works in the terminal but still returns the same erro code using the php exec().
Has anyone got any ideas?
Thank you.
If you got the module loaded, use the php-ffmpeg api instead of exec. Run exec only if the module wasn't loaded or else you've loaded the module for nothing (meaning you're not using the module at all).
The error you recive is from ffmpeg binary (not the extension, though you're not using the extension at all) , so search for ffmpeg status 127 error to resolve the problem related to ffmpeg.
I just had the same issue (ffmpeg not running through exec/system)
I sorted it by using /usr/bin/ffmpeg instead of just ffmpeg

Categories