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
Related
The problem is faced while running node command (which generates PDF file for given link) on Linux through PHP exec/passthru/system functions. Actually, I am trying to create PDF file through headless chrome using Puppeteer node module. Everything worked fine in Windows system but as soon as the same code was moved on production server (which uses Linux), the exec/passthru commands began to throw 127 return code errors. Please note that same node command works without any problem when run directly on terminal .
Also, Apache has write permissions in directory where file is being generated and command was also tried by giving the absolute paths but nothing seems to be working
The format of command is like this
"node script-generating-code.js http://www.url-of-page.com/"
I have downloaded Tesseract OCR, installed it on windows and set its path variable and test it as well.
https://github.com/thiagoalessio/tesseract-ocr-for-php
I have downloaded its php script too and did some basic testing.
echo $this->buildTesseractCommand();
exec(trim($this->buildTesseractCommand()));
The command
echo tesseract C:\xampp\htdocs\OCR\test\images\hello.png C:\xampp\htdocs\OCR\test\temp\29847.txt
where hello.png is file to read characters from and 29847.txt is random file generated from cmd in which output is stored. although the same command is working directly through cmd.
But sadly the command is not working through php and no .txt file is generated , but when I paste the same in my command prompt, it works and file is generated.
I have tried system(), exec() and passthru() functions to run command but its not working in any :(
Any idea how to run it or any alternatives ?
When I am using wkhtmltopdf in the terminal it works fine and pdf is generating correctly.
But when I am trying to use this in the php using 'system' command, it fails and gives apache error that 'cannot connect to X-server'.
In php, I used like this.
system("wkhtmltopdf $url output.pdf");
I tried 'exec' instead of system but giving the same problem.
Please help me out.
It might be a permission error if it works via command line but not PHP. Are you working locally or on a remote server? If you're on shared hosting, try contacting support to see if you have permission to call system, exec, or shell_exec.
Alternatively, try redirecting your standard error to a text file, maybe that will steer you a bit in the right direction:
system("wkhtmltopdf $url output.pdf 2> /tmp/error.txt");
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
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