I'm trying and failing to use tesseract php. I get this error:
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException: Error! The command "tesseract" was not found. Make sure you have Tesseract OCR installed on your system: https://github.com/tesseract-ocr/tesseract
The current $PATH is C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Users\Peppe\AppData\Local\Microsoft\WindowsApps;C:\Users\Peppe\AppData\Roaming\Composer\vendor\bin in C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php:48 Stack trace: #0
C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\TesseractOCR.php(26): thiagoalessio\TesseractOCR\FriendlyErrors::checkTesseractPresence('tesseract') #1 C:\xampp\htdocs\index.php(7): thiagoalessio\TesseractOCR\TesseractOCR->run() #2 {main} thrown in C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 48
I'm using windows 10 with xampp installed in C:\xampp. php version 7.4
I installed tesseract.exe from https://github.com/UB-Mannheim/tesseract/wiki both x32 and x64
I used composer to install the https://github.com/thiagoalessio/tesseract-ocr-for-php and it gave no error.
<?php
require_once 'C:\Users\Peppe\vendor\autoload.php';
use thiagoalessio\TesseractOCR\TesseractOCR;
$ocr = new TesseractOCR("caption.jpg");
$content = $ocr->run();
echo $content;
?>
finally, the caption.jpg is in the htdocs folder, the main folder and same folder as index.php where the aforementioned code appears.
any solutions?
I found the answer:
the $PATH variable is taken from Windows. To set it right search for "system environment variables", click "environment variables", edit PATH and add the tesseract software folder, for example C:\Program Files\Tesseract-OCR
In my case I have to add new variable tesseract with full path C:\Program Files\Tesseract-OCR\tesseract.exe as showing in below screenshot
To install TESSERACT OCR and use it in PHP
You must perform the following steps:
(in my explanation, I assume you are on windows)
url src = https://tesseract-ocr.github.io/tessdoc/Installation.html
1- Download the TESSERACT software from URL:
https://github.com/UB-Mannheim/tesseract/wiki
2- From your composer, you must install:
url: https://packagist.org/packages/thiagoalessio/tesseract_ocr
composer require thiagoalessio/tesseract_ocr
3- Then, it is important to do things in the following order:
Your TESSERACT software (step 1) is installed in a directory
which will certainly be (it's up to you to check in your system)
folder = C:\Program Files\Tesseract-OCR
It is absolutely necessary to add this folder in the windows environment variables at the PATH level (user and system)
4- Then you restart your web environment (WAMP, LARAGON ...)
5- Verification that TESSERACT is operational.
Go to your CMD and write:
tesseract --version
Reply somethink like that :
tesseract v5.3.0.20221222
leptonica-1.78.0
libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
Found AVX2
Found AVX
Found FMA
Found SSE4.1
Found libarchive 3.5.0 zlib/1.2.11 liblzma/5.2.3 bz2lib/1.0.6 liblz4/1.7.5 libzstd/1.4.5
Found libcurl/7.77.0-DEV Schannel zlib/1.2.11 zstd/1.4.5 libidn2/2.0.4 nghttp2/1.31.0
6- Operation test from a PHP script
uses an image on a white background with text
<?php
$app_class = 'thiagoalessio\TesseractOCR\TesseractOCR';
$file = 'C:/Users/admin/Desktop/im2.jpg';
$class = new ReflectionClass($app_class);
$infoImg = $class->newInstanceArgs();
$infoImg->lang('eng','jpn','spa','fr');
$infoImg->image($file);
$infoImg->withoutTempFiles();
$resultat = $infoImg->run();
var_dump($resultat);
?>
Related
Fatal error: Uncaught Error: Call to undefined function ImageCreate() in C:\xampp\htdocs\the_base\qr\libs\phpqrcode\qrimage.php:74 Stack trace: #0 C:\xampp\htdocs\the_base\qr\libs\phpqrcode\qrimage.php(32): QRimage::image(Array, 5, 4) #1 C:\xampp\htdocs\the_base\qr\libs\phpqrcode\qrencode.php(494): QRimage::png(Array, 'temp/184011_inf...', 5, 4, false) #2 C:\xampp\htdocs\the_base\qr\libs\phpqrcode\qrencode.php(286): QRencode->encodePNG('\tRoll no: 18401...', 'temp/184011_inf...', false) #3 C:\xampp\htdocs\the_base\qr\index.php(57): QRcode::png('\tRoll no: 18401...', 'temp/184011_inf...', 0, 5) #4 {main} thrown in C:\xampp\htdocs\the_base\qr\libs\phpqrcode\qrimage.php on line 74
This is the error I am getting since I've updated my XAMPP. This same code has worked perfectly with an older version of xampp but when I updated it, the code suddenly started to give this error
I am trying to create a QR code in png format and make it downloadable
I did a little research about it, it said that the GD lib was missing in the PHP but all the steps shown to fix it were of LINUX OS, I am currently using Windows.
go to php.ini file xampp/php/php.ini
search for ;extension=gd and ;extension=gd2
remove the ; from both lines, then restart the server
there might be two cases:
1.gd installed and disabled
2. gd not installed and disabled
for first case:
on XAMPP server click on Apache config -> php.ini
1.open this file in notepad
2. search for ;extension=gd or ;extension=gd2
3. remove the colon ; ( just extension=gd)
4. save it .
for second case gd not installed:
check it through:
(on browser) localhost/dashboard
xampp dashboard opens up, on upper left go to phpinfo()
search for gd section if not present then follow down:
1.open folder : xampp/php/ext
2. then find and Copy php_gd.dll and paste it into the following folder
3.C:\Windows\System32
4. paste php_gd.dll here.
5. restart xampp server and run.
for better explanation:
https://www.geeksforgeeks.org/how-to-install-php-gd-in-windows/
It seems like the php_gd2 extension isn't enabled.
you have to enable it in php.ini. To do this, simply open php.ini and uncomment (remove the leading ;) the following line:
extension=php_gd2.dll
Uncaught Error: Call to undefined function CodeIgniter\locale_set_default()
in C:\xampp\htdocs\sunpay-ci4\system\CodeIgniter.php:184
Stack trace:
#0 C:\xampp\htdocs\sunpay-ci4\system\bootstrap.php(181): CodeIgniter\CodeIgniter->initialize()
#1 C:\xampp\htdocs\sunpay-ci4\public\index.php(36): require('C:\\xampp\\htdocs...')
#2 {main} thrown in C:\xampp\htdocs\sunpay-ci4\system\CodeIgniter.php on line 184
I don't understand this error, the first page works if I drop this package.
Try opening php.ini from the control panel:
Apache row -> Config -> php.ini
Then enable intl extension by removing ; in front of extension=intl
Edit: the reason it fails is because the intl extension is disabled by default in xampp
Recently I stuck on the same problem on CI version 4.0.4.
Follow the steps to fix it.
Click on "config" from the xampp control panel.
Then click on php.ini option.
Then it will open on your default text editor application (for me it is Notepad). then click on find option.
Then search for ";extension=intl".
replace ";extension=intl" with "extension=intl".
That's all. Thanks.
get your php version by put this code : phpinfo();die(); in your index.php after <?php so it looks like like <?php phpinfo();die();
PHP Version 7.2.24-0ubuntu0.18.04.7
jump to /etc/php/{your php version}/apache2 folder; example : /etc/php/7.2/apache2 and open php.ini then find ;extension=intl and remove the semicolon ;
open your terminal then write or copy paste this command sudo systemctl restart apache2 and press ENTER
open your CI 4 again in your browser.
Welcome to CodeIgniter 4.0.4
The small framework with powerful features
==============================================================================
if you still get the same error please try to install intl extension using this command in your terminal:
sudo apt install php{your php version}-intl
sudo systemctl restart apache2`
example :
sudo apt install php7.2-intl
sudo systemctl restart apache2
open your CI 4 again in your browser.
Welcome to CodeIgniter 4.0.4
The small framework with powerful features
=============================================================================
#NB :
dont forget to remove phpinfo();die(); in the first step
sorry for my bad english
Just go to the mentioned line in display in error.
C:\xampp\htdocs\sunpay-ci4\system\CodeIgniter.php:184
You can find it here: root folder/system/CodeIgniter.php
on line no 184 you will find the below code.
locale_set_default($this->config->defaultLocale ?? 'en');
just comment it like this.
#locale_set_default($this->config->defaultLocale ?? 'en');
Now, the code is working.
1.search for intl and uncomment this extension in php.ini file by removing ; from begin of line extension=intl
2. restart Apache service by stop and starting it again from xampp control panel
When i started a new project i got this error on welcome screen. Fatal error: Uncaught Error: //pp\Views\welcome_message.php:222 Stack trace: #0 {main} thrown in. It appears like there is a problem with the installation of codeigniter but in fact it is an echo error in line 222 of the welcom_message.php page go there an remove the <?= CodeIgniter\CodeIgniter::CI_VERSION ?> from line 222 it should look like this
<div class="heroe">
<h1>Welcome to CodeIgniter </h1>
<h2>The small framework with powerful features</h2>
</div>
Then it will echo hello screen correctly
Usually to get round this try these three points:
Ensure .writable folder is writable with file permissions 0777 (must have leading zero)
Try setting the following in index.php -> $_SERVER['CI_ENVIRONMENT'] = 'development'; and toggle with $_SERVER['CI_ENVIRONMENT'] = 'production' in .env file;
Access this file(CodeIgniter.php) in the following directory: project_folder/vendor/codeigniter4/framework/system/CodeIgniter.php
public function initialize()
{
if( function_exists('locale_set_default' )):
locale_set_default($this->config->defaultLocale ?? 'en');
endif;}
if your have installed Apache, PHP, MYSQL manually, then set locale to app in .env file:
app.locale = "en"
save and restart apache service
I find a problem to use tesseract_ocr in php, I follow this tutorial https://github.com/thiagoalessio/tesseract-ocr-for-php.
I install tesseract_ocr use composer :
$ composer require thiagoalessio/tesseract_ocr
this is my folder structure in localhost :
this is mycode :
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
require __DIR__ . "/vendor/autoload.php";
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('images/8055.PNG'))
->whitelist(range('A', 'Z'))
->run();
?>
</body>
</html>
this is my php version :
and in the browser I get this error :
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException: Error! The command "tesseract" was not found. Make sure you have Tesseract OCR installed on your system: https://github.com/tesseract-ocr/tesseract The current $PATH is C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk1.8.0_73\bin;C:\Users\frank\AppD in C:\xampp\htdocs\ocr\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 48
please anyone help me to solve this problem.
Thanks.
You need to install Tesseract OCR on your pc from here:
https://github.com/tesseract-ocr/tesseract
Then your code should be(just in case you are on windows, C:\Program Files\Tesseract-OCR\tesseract.exe is the path of Tesseract engine):
echo (new TesseractOCR($img_url))
->executable('C:\Program Files\Tesseract-OCR\tesseract.exe')
->whitelist(range('A', 'Z'))
->lang('eng')
->run();
Make sure the tesseract folder is in your path.
If you're unsure what I'm saying, click on the start button and type "edit the system environment variables". Click Environment Variables, under "System variables" click on the line that has "Path" on the far left, and click edit. Click "New" and put in the path to your executable, depending on if you're using the 64 bit or 32 bit version. In my case it was "C:\Program Files\Tesseract-OCR".
You can test this now by opening a new command prompt (if you had an old one open, it won't have the new path variable), and type tesseract and hit enter. You should see:
Usage:
tesseract --help | --help-extra | --version
tesseract --list-langs
tesseract imagename outputbase [options...] [configfile...]
OCR options:
-l LANG[+LANG] Specify language(s) used for OCR.
NOTE: These options must occur before any configfile.
Single options:
--help Show this help message.
--help-extra Show extra help for advanced users.
--version Show version information.
--list-langs List available languages for tesseract engine.
If you do, then it's installed and globally working on your machine now and should work with PHP. If you want to get it working without composer, look up my other answer about that on here.
So I'm currently using "Imagick" extension for a symfony project, but I get this error:
ClassNotFoundException: "Attempted to load class "Imagick" from the global namespace. Did you forget a "use" statement?"
Strangely, it's working fine in all native php script, but not working in symfony project!
I did some research and I found that I need to enable imagick for CLI also .. but I didn't find any method explain how to make it.
So, I verified Imagick installation by this code snippet:
<?php
header('Content-type: image/jpeg');
$image = new imagick("C:/wamp64/www/test/image.jpg");
$image->thumbnailImage(100,0);
echo $image;
and I can see the image loaded correctly.
Also, when I run this script from the browser:
<?php
if (extension_loaded('imagick')){
echo 'imagick is installed';
} else {
echo 'imagick not installed';
}
?>
I get :
imagick is installed
But when I execute this file from command-line interface, I get :
imagick not installed
In the Symfony project I get this error log:
Uncaught PHP Exception Symfony\Component\Debug\Exception\ClassNotFoundException: "Attempted to load class "Imagick" from the global namespace. Did you forget a "use" statement?"
Symfony function
private function createThumbnail($path, $dest, $width, $height)
{
$im = new \Imagick();
$im->pingImage($path);
$im->readImage($path);
$im->thumbnailImage($width, $height);
$white=new \Imagick();
$white->newImage($width, $height, "white");
$white->compositeImage($im, \Imagick::COMPOSITE_OVER, 0, 0);
$white->setImageFormat('jpg');
$white->writeImage($dest);
$im->destroy();
$white->destroy();
}
Environment
PHP Version => 7.1.9
System => Windows 10
Server => Wamp64
Symfony version => 3.1
Compiler => MSVC14 (Visual C++ 2015)
Architecture => x64
imagick module version => 3.4.3
ImageMagick version => ImageMagick 6.9.3-7 Q16 x64 2016-03-27
The complete ImageMagick/Symfony installation steps are the following (here for Windows):
Download the package from https://pecl.php.net/package/imagick/3.5.1/windows
Extract from php_imagick-….zip the php_imagick.dll file, and save it to the ext directory of your PHP installation
Extract the dependencies
• For PHP 5.x/7.x: Extract from ImageMagick-….zip the DLL files located in the bin folder that start with CORE_RL or IM_MOD_RL or FILTER, and save them to the PHP root directory (where you have php.exe), or to a directory in your PATH variable:
• 17 files CORE_RL*.dll
• 126 files IM_MOD_RL*.dll
• 1 files FILTER*.dll
• For PHP 8.x: Extract from php_imagick-….zip the DLL files that start with CORE_RL or IM_MOD_RL or FILTER, and save them to the PHP root directory (where you have php.exe), or to a directory in your PATH variable
Add this line to your php.ini file: extension=php_imagick.dll
Restart the Apache/NGINX Windows service (if applicable)
Check if the install is correct through phpinfo() for which a specific imagick block has been added
Don’t forget to add use Imagick; to your php file
I found the solution, I put the answer for someone who have the same issue:
you should add the following lines
;on Windows:
extension=php_imagick.dll
;on UNIX:
extension = imagick.so
to C:\wamp64\bin\php\phpx.x.x\php.ini
not to C:\wamp64\bin\apache\apachex.x.x\bin\php.ini
because the first php.ini is the file used by PHP CLI, so by the Symfony Local Web Server.
Happy coding!
I have a WAMP server on Win 8 running Laravel 4 and I'm trying to get wkhtmltophp to work properly.
I ran the Windows installation program I downloaded from here (the 64-bit "Windows (MSVC 2013)").
I'd first installed it into C:\Program Files\wkhtmltopdf, then I tried installing it into the laravel /vendor directory under C:\Program Files (x86)\Apache Group\Apache2\htdocs\gitt\vendor\wkhtmltopdf
naturally I changed my folder to match under /app/config/local/laravel-pdf.php and in this file I have
return array(
//'bin' => '/usr/bin/wkhtmltopdf'
'bin' => base_path() . '/vendor/wkhtmltopdf/bin'
);
And every time I run the script, I get the error "proc_open(): CreateProcess failed, error code - 5"
Not sure what I'm missing. Another developer, on a Mac, was able to install it on his side, so laravel also has the /vendor/mikehaertl/phpwkhtmltopdf installed, so I changed line 92 to:
class WkHtmlToPdf
{
#protected $bin = '/usr/bin/wkhtmltopdf';
protected $bin = '/Program Files (x86)/Apache Group/Apache2/htdocs/gitt/vendor/wkhtmltopdf/bin/wkhtmltopdf.exe';
etc......
Still got the same error. I'm lost! Any help would be greatly appreciated! :)