OCR (Optical Character Recognition) in PHP

Ever wanted to extract text from images using PHP? That doesn’t seem trivial, does it? But you will find it’s not that hard after reading this article, so let’s get started!

 
First- we need an OCR engine. I once written such thing in pure PHP, but it was so slow that it wasn’t usable with bigger images. PHP is just not a perfect thing for such tasks.

 
Luckily there is a free OCR engine available for many platforms- including Windows and Linux that we can use as command-line app…

Few very useful PHP functions

In this post I would like to present a few PHP functions which I created for projects I worked on and which I found very useful many times.
The functions are not super-advanced, but really handy. You can use them freely as they all are licensed under MIT.
I think there is a big chance you will find them useful too. If you do- please leave a comment, thanks!

PHP Error: unserialize() [function.unserialize]: Error at offset 118 of 512

Lately I got this error in my script while trying to decode serialized UTF-8 string:

unserialize() [function.unserialize]: Error at offset 118 of 512

Here’s a simple solution I found.

(Almost) All PHP functions with simple explanations in one place

AMQP
AMQPConnection::__construct – Create an instance of AMQPConnection
AMQPConnection::isConnected – Determine if the AMQPConnection object is still connected to the broker.
AMQPExchange::bind – The bind purpose
AMQPExchange::__construct – Create an instance of AMQPExchange
AMQPExchange::declare – Declare a new exchange on the broker.
AMQPExchange::delete – Delete the exchange from the broker.
AMQPExchange::publish – Publish a message to an exchange.
AMQPQueue::ack – Acknowledge the receipt [...]

Read and write BMP in PHP: imagecreatefrombmp + imagebmp

This is an updated class to use BMP format in PHP. Previous version is
here. If all you need is loading and saving 24bit BMP files- you can use previous version. It has less code so works a bit faster.
This version saves 24bit BMP files and loads 1, 4, 8, 24 and 32 bit BMP files.

PHP Error: Fatal error: Unable to read X bytes in Y.php on line 0

“Fatal error: Unable to read X bytes in Y.php on line 0″ is an error I got once after moving a site to another server. The file was encoded with Zend Optimizer so I could not check what is happening on line 0 that could make any problems.

PHP Class: Get screenshot (thumbnail) of any website

If you use PHP 5.2.2+ on Windows you can use function imagegrabwindow to make a screen shot of a website opened in Internet Explorer. However there is also a lot of websites which can screen shot any site for you- for free!
So- here’s a simple PHP class which will get a screen shot of any [...]

PHP Error “headers already sent”

If got an error like this one:

Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at E:\websites\index.php:3) in E:\websites\index.php on line 5

it means you tried to change headers of the file after sending the content of the file.

Load and save Bmp in PHP: imagecreatefrombmp + imagebmp

If you want to open or create 24bit BMP images with PHP- just grab my simple library.

Open TGA with PHP: imagecreatefromtga

Need to read TGA files in PHP? Here’s an implementation of imagecreatefromtga, which reads 24 bit TGA images both RLE compressed and uncompressed. You can use it as any other imagecreatefrom* function.

 
TopOfBlogs Web Development & Design Blogs