I built a pdf generator script for one of my clients and everything works properly. He then decided that he wanted me to create a thumbnail image from the PDF to display on another page, so I came across PHMagick and that seemed to do the trick.
The following code worked on my building server (iPage -- I think it's debian?), but now that I've moved it to his VPS, it is no longer working. FPDF has no trouble generating the pdf, so it is not a permissions issue.
Code:
require("phmagick/phmagick.php");
$pdf->Output("pdf.pdf");
$p = new phmagick('','pdf.png');
$p->debug = true;
$p->resize(800);
$p->acquireFrame("pdf.pdf");
This code returns the following error:
Error executing "convert "pdf.pdf"[0] "pdf.png"" return code: 127 command output :"sh: convert: command not found"
I have not changed any of the code since I moved it from the original server, and I just copied the entire site over, so why is PHMagick not working now? How do I get it to recognize convert.php in the plugins folder?
Just a note: I am only using PHMagick, not the whole of ImageMagick.
PHMagic appears to be using the command line convert command in background.
Most likely that command is simply not installed on the server.
PHMagic use the command line convert,composite etc... commands in background.
These commands are only available if ImageMagick is installed in your server.
In your previous server ImageMagick must have been installed.
Ipage sometimes do not pre install ImageMagick on their VPS servers. And you might not be able to install it your self ( through terminal login using ... yum install ImageMagick ) coz you will be prompt for root password.
To make sure the ImageMagick binaries are installed in ur server, in ur case the convert command,
type this command in the ssh terminal...
whereis convert
If the path to the convert command is not shown, it means you need to install ImageMagick.
You will have to open a support ticket and ask them to install it for you
As arkascha said, you'll need to install imagemagick. Try yum install imagemagick since you're running CentOS.
EDIT: May be a different capitalization: ImageMagick
Related
I realize that Imagick has it's own command line executables, but why whenever I try to run an Imagick command written in PHP it breaks my script and exits without warning?
Take something simple:
<?php
$imagepath = realpath('1.gif');
var_dump('111');
$image = new Imagick($imagepath);
var_dump('222');
var_dump($image);
Running php -f imagick.php on my command line interface just simply outputs string(3) "111" and then immediately exits once it hits any Imagick function.
Imagick is properly installed on my machine, and if I do a php -m it shows Imagick as an installed module.
Is there anyway to get it working in command line scripts (aside from using exec())?
I was slightly worried that it wouldn't work on cron jobs, but I just did a quick test and it seems to be working within that (least on VPS).
Am trying from Windows x64 WAMP server PHP v7.1.16.
Note: To clarify, this is just a command line issue. Imagick is installed correctly, no issue with syntax, I've been using it for months in the browser with no issues.
Even command line attempts.. php -d display_errors imagick.php, same, dies upon impact of IM with no notice php -n -l -d display_errors -d display_startup_errors imagick.php brings back 'No Syntax Errors'. It's peculiar, nothing should simply kill the script (although it does try to load for a second before it essentially breaks out of the script no matter where it's at) without any notice.. then again since there's no issue running it in the browser over and over, so I don't think there is any errors (especially sampling my above one liner Imagick initalization).. it's just a CLI thing that I do not understand.
This was a local issue, apparently.
I recently reinstalled Windows and subsequently reinstalled Imagick and PHP.
Anyone else having similar issues I recommend reinstalling Imagick (it's a big pain to install -- recommend using these references for installing on a Windows 10 machine:
Installing Imagick for PHP 7 on Windows 10
Proper Way to CLI PHP within WAMP (WAMP64), while switching between Multiple PHP Versions on Windows 10
Also I've yet to try this personally, but by the looks of it, seems a better method for imagick integration with PHP: ImageMagickPHP (Imagick PHP Class that utilizes command line exec as opposed to the PHP version).
I want to run tesseract-OCR in PHP. I want to develop a web api for image to text conversion. Kindly suggest a way. I tried this command:
<?php
shell_exec("c:\xampp\htdocs\Tesseract-OCR\tesseract.exe a:\lool.jpg a:\out.txt");
echo "edede";?>
but there is no output in a:\ directory
teseract is working fine from command prompt and shell_exec is also working fine in opening other executables
I am using Php in Linux Cent OS. I wanted to convert PDF to SWF, So I use SWFTools. SWFTools consists of pdf2swf command, which is executing fine when I use it in command line. But the command is not working when I execute it through php.
Error: command not found
I have found the extensions are up to date.
Anything else is missing in between?
Use the full path.
The path environmental variable will be different when running under PHP, since that will run as another user.
I work at a small computer shop, and we have to analyze windows minidumps all the time. My idea was to install the Windows Debugging Tools on a windows PC and use apache/PHP as an interface to it. That way I could just set up an HTML upload form that would accept the minidump file, run it through KD, then spit out the output.
It nearly works. I created a special user just for apache so I could assign it write privaleges to C:\symbols, and I use the following code:
<?php
$kdScript = "\"\\Program Files\\Debugging Tools for Windows (x86)\\kd.exe\" -c \"!analyze -v;Q\" -y srv*c:\symbols*http://msdl.microsoft.com/download/symbols -z ";
$kdScript .= $_FILES["myFile"]["tmp_name"];
$output = `$kdScript`;
print("<pre>$output</pre>");
?>
The problem I'm having is that the symbols are not downloaded as they should be. I've verified apache is running as the user I think it is by calling "whoami" from inside backticks. I've verified that I can run the windows version of wget from within backticks, so I have access to the network. I can file_put_contents() into a new file under C:\symbols, so I have file creation permissions.
Also, I tried having PHP simply output the command to the browser so I could copy and paste it into a terminal. I was able to run a command prompt as my apache user via "runas", paste the command from PHP's output into the prompt, and it worked as expected, downloading all the symbols it needed to C:\symbols. Of course, I had to point it to a dump file NOT in the PHP temp directory, but this shouldn't make a difference.
What could be the problem? Just as a side note, all of this is local on a trusted pc in a company that has a total of 3 employees/owners. Security for this project is irrelavent.
Not sure what your exact problem is, but the symbol server client code is finicky and not very debuggable, it took us lots of tinkering to implement our version of this. You can always direct folks there or use it yourself:
http://www.osronline.com/page.cfm?name=analyze
-scott
I’m attempting to convert PDF files into PNGs. It works great from the command line (I do have GhostScript 8.64 installed). But from PHP I’m having a problem:
code:
$im = new Imagick($pdf_file); // this is where it throws the exception below
output:
Fatal error: Uncaught exception ‘ImagickException’ with message ‘Postscript delegate failed `23_1235606503.pdf’: No such file or directory # pdf.c/ReadPDFImage/612′ in get_thumbnail.php:93
Stack trace:
\#0 get_thumbnail.php(93): Imagick->__construct(’…’)
etc. etc.
I'm not sure what I'm doing wrong here, but I suspect it has something to do with my server configuration somewhere. I'm running:
Apache 2.2.11
PHP 5.2.8
ImageMagick 6.4.8-9
GhostScript 8.64
Finally figured this out. The GhostScript executable (gs) wasn't in Apache's environment path. It was in /usr/local/bin. Though I tried several ways to add /usr/local/bin to the path, I did not succeed. I ended up putting a symlink for gs in the /usr/bin directory. Now everything works perfectly.
I don't have the "reputation" on Stackoverflow to add a comment inline above, but there is an extra step I had to perform to get this working on my Mac with the latest Sierra update.
When you enter the command:
sudo ln -s /usr/local/bin/gs /usr/bin/gs
On the Mac, you may get the error, "Operation not Permitted".
Apparently Apple made a change that the "bin" directory is not editable, unless you disable SIP (System Integrity Protection).
So here are the steps to do that:
Reboot your Mac into Recorvery Mode by restarting your computer and holding down "Command + R" until the Apple logo appears on your screen.
Click Utilities > Terminal
In the Terminal window, type in crutil disable and press "Enter"
Restart your Mac.
I just went through these steps and now my Ghostscript works great and I successfully converted a PDF to JPG.
I am successfully doing this. Here is the code that I am using to do the conversion. We are using this solution commercially. I know this question has been out there for awhile, but it may still help you.
//Convert PDF contract to image using ImageMagik and Ghostscript
// NOTE: This will need to be change if running on Linux
$source = $appDir."\\".$clientID."\\".$clientID.".pdf";
$dest = $appDir."\\".$clientID."\\".$clientID.".jpg";
//print("c:\\IM\\convert.exe $source $dest ");
exec("c:\\IM\\convert.exe $source $dest ");