OCR in PHP: Read Text from Images with Tesseract

Optical Character Recognition (OCR) is the process of converting printed text into a digital representation. It has all sorts of practical applications — from digitizing printed books, creating electronic records of receipts, to number-plate recognition and even circumventing image-based CAPTCHAs.

Robotic eye

Tesseract is an open source program for performing OCR. You can run it on *Nix systems, Mac OSX and Windows, but using a library we can utilize it in PHP applications. This tutorial is designed to show you how.



To keep things simple and consistent, we’ll use a Virtual Machine to run the application, which we’ll provision using Vagrant. This will take care of installing PHP and Nginx, though we’ll install Tesseract separately to demonstrate the process.

If you want to install Tesseract on your own, existing Debian-based system you can skip this next part — or alternatively visit the README for installation instructions on other *nix systems, Mac OSX (hint — use MacPorts!) or Windows.

Vagrant Setup

To set up Vagrant so that you can follow along with the tutorial, complete the following steps. Alternatively, you can simply grab the code from Github.

Enter the following command to download the Homestead Improved Vagrant configuration to a directory named ocr:

git clone https://github.com/Swader/homestead_improved ocr

We’re not going to be using Laravel, so change the Nginx configuration in Homestead.yml from:

    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public


    - map: homestead.app
      to: /home/vagrant/Code/public

You’ll also need to add the following to your hosts file:       homestead.app

Installing the Tesseract Binary

The next step is to install the Tesseract binary.

Because Homestead Improved uses a Debian-based distribution of Linux, we can use apt-get to install it after logging into the VM with vagrant ssh. It’s as simple as running the following command:

sudo apt-get install tesseract-ocr

As I mentioned above, there are instructions for other operating systems in the README.

Continue reading %OCR in PHP: Read Text from Images with Tesseract%

Source: Sitepoint

AIDL for Sharing Functionality between Android Apps

While building Android apps you might sometimes need to expose functionality which other processes can use. As these calls are between separate processes, they cannot be a simple function, as on Android process cannot access the data in another.

To pass data between processes, it needs to be marshaled and unmarshaled accordingly. This marshaling and unmarshmaling of data to primitive types is so the OS can understand it passing over IPC can be tedious and error prone if done manually. Android interface definition language (AIDL) helps solve this problem. AIDL generally has three components which are:

Continue reading %AIDL for Sharing Functionality between Android Apps%

Source: Sitepoint

Monitor and Control Applications Using Supervisor: Part 1

is a monitoring tool which controls various child processes and
handles starting/restarting of these child processes when they exit
abruptly or exit due to some reasons. It can be extended to control
the processes via the XML-RPC API over remote locations without logging
in to the server. I will cover the XML-RPC API in the second part of this two-part series.

In the first part of this tutorial series, I will take you through how to set up Supervisor to work with our application. For this, I will create a trivial application in Flask along with Gunicorn to act as our WSGI HTTP server. 

I assume that you have a basic understanding of Flask, Gunicorn and environment setup best practices using virtualenv to be followed while developing a Python application.

Installing Packages

The following packages need to be installed for developing and controlling the application we’ll be developing.

The Trivial Application

I will now create a trivial application in Flask. This application is small but will meet the needs of this tutorial.

Below is the structure of the application:


In the file above, the application has been configured and initialised.


In the file above, I have created a simple Hello World endpoint.

To run the application as a process, we can use Gunicorn. To check if Gunicorn is working as expected, just run the following command from inside the application folder.

After this, point your browser to to see the application’s
home page.

Configuring and Using Supervisor

Now, we need to do the same using Supervisor so that this runs as a daemon and will be controlled by Supervisor itself rather than human intervention. 

First of all, we need a Supervisor configuration file. Supervisor, by default, looks for an etc folder that has a file named
supervisord.conf. In system-wide installations, this folder is /etc/, and in virtualenv,
it will look for an etc folder in virtualenv and then fall back to /etc/.

In the case of a system-wide installation, run:

In the case of virtualenv, from inside the virtualenv root folder, run:

The echo_supervisord_conf program is provided by
Supervisor; it prints a sample config file to the location specified. This will create a file named supervisord.conf at the location specified in the above command.

To configure Supervisor for our application, add the following block somewhere in this file:

Here we configure the command that needs to be run and from which directory location it needs to do so under which user. Also specified is whether to restart the application in case of any failure. The log files’ locations can also be specified. There are many other configuration options, which can be looked up in the official documentation of Supervisor.

Make a note that one should never run the applications as a root user.
This is a huge security flaw as the application crashes, which
can harm the OS itself.

To run the application using Supervisor, run the following commands:

The first command invokes the supervisord server, and the next one gives a status of all
the child processes.

Every time you make a change to your application and then wish to restart Gunicorn in order
for it to reflect the changes, run the following command:

You can also give specific processes instead of restarting everything: 

Supervisor also provides a Web UI interface which can be enabled by enabling the inet_http_server configuration block in supervisord.conf. This Web UI can be looked up on http://localhost:9001/.


In this tutorial, we have seen how to configure Supervisor and use it to run an application as a daemon process and control the processes collectively or selectively. In the second part of this tutorial series, we will see how to control and interrogate Supervisor and its programs/processes using the XML-RPC API.

Source: Nettuts Web Development

Web Development Reading List #109


What’s going on in the industry? What new techniques have emerged recently? What insights, tools, tips and tricks is the web design community talking about? Anselm Hannemann is collecting everything that popped up over the last week in his web development reading list so that you don’t miss out on anything. The result is a carefully curated list of articles and resources that are worth taking a closer look at. — Ed.

Insecure Login Fields

Building products or software is not easy. As developers, we are constantly aware of this fact. As managers, we also know this. As product owners, hell yes. But the most important thing is to also teach our customers. It’s important that we figure out a holistic approach to build a product that pleases the user and all others who are involved.

The post Web Development Reading List #109 appeared first on Smashing Magazine.

Source: Smashing Magazine

The Vital Guide to Interviewing Web Developers

This guide offers a sampling of effective questions to help evaluate the breadth and depth of a candidate’s mastery of web development, including client-side, server-side, transport, and database related topics.

Before we embark on the journey of identifying world-class web developers, we must first define exactly what we mean by “web development”. Are we referring to the development of a web site? Or the development of a web service? Or the development of a complex web-based application? The truth is that web development is an extremely broad term that can legitimately encompass any or all of the above. Accordingly, this guide touches on multiple aspects of web development, some or all of which will be relevant to the specific context in which you may be looking to hire.

This guide intentionally focuses on the conceptual and architectural underpinnings of web development, rather than delving into the specifics of any specific web technologies (such as JavaScript, Ruby on Rails, PHP, and so on). Accordingly, this guide presents “technology-agnostic” web developer interview questions relating to:

Web Concept/Architecture

Admittedly, doing justice to many of the topics herein would warrant posts of their own. Nonetheless, this guide strives to provide at least a meaningful overview of key issues and topics relating to web development in which a highly-experienced web developer can be expected to be well-versed.

Client-side browser-based development

Client-side (browser-based development)

Browser-based development presents numerous unique challenges to the developer, ranging from cross-browser anomalies, to sandbox limitations, to diverse performance characteristics across a wide array of client platforms and devices. Adept client-side web developers will be highly skilled at navigating these obstacles.

Q: Discuss at least three areas of focus on the client side to help reduce page load time.

Performance is central to a user’s experience with any application. Users have become increasingly intolerant of slow page load times and, knowing this, the large search engines actually quantify that time for each of the pages that their bots crawl.

Making the initial page request, getting the initial response contents of a page to the client, parsing that content and making subsequent requests for resource items (which in themselves are a round trip to and from the server), and then running any JavaScript can all contribute to page load time.

There are in fact numerous techniques to employ and areas to focus on to help improve page load time. Here are just a few examples:

  • Avoid “render blocking”. When the browser’s parser engine encounters a tag in the HTML that accesses some external resource (such as a <script>, <image>, <iframe>, etc.) the engine pauses to wait for that resource to download fully to the client before continuing. Even worse, in the case of a <script> tag with a src attribute, the browser will also execute that script before it moves on to process the rest of the page. This becomes particularly problematic when that script may subsequently make another request. Most browsers provide an async attribute that you can add to those tags to avoid this type of blocking. Another strategy is to identify resources that you can delay loading until they are actually needed.
  • Optimize images. Probably the largest resources you will load into a page are your images. Optimizing them for transport can prove to be very beneficial, as appropriate sizing can substantially reduce page load times. For example, don’t use a 600px by 400px image for a 120px by 80px thumbnail. It’s also helpful to pick the best compression format and to turn off certain format features.
  • Minimize round-trip requests. The round-trip of retrieving resources (images, etc.) from the server can be a huge problem for page load times. Since the fewer requests a page makes, the faster it will be, one technique to help performance is to combine resources together into fewer requests where possible. For example, non-user generated images are a prime candidate here. A round-trip to the server just to retrieve a single 16×16 smiley face emoticon, for example, is extremely inefficient.

Continue reading %The Vital Guide to Interviewing Web Developers%

Source: Sitepoint

How to Use Modernizr Responsibly

If you like playing with new features which might not be available in all browsers, you have surely already tried Modernizr. This library allows to test whether the features you want are available or not. As Modernizr adds some CSS classes on the html element to indicate if a given feature is available, you might be tempted to directly include it in the head tag to know as soon as possible if the features you want are available or not.

This approach was what the developers of Modernizr themselves recommended at the beginning. The problem with it is that it’s not compatible with the responsible approach we all should have. That’s why Paul Irish, one of the developers of the project, shared his thoughts about how Modernizr should be included. These thoughts inspired this article. In it we will talk about why we should adopt a responsible approach when we want to use Modernizr. Then, we will see some ways to put this approach into practice when possible.

Why Caring about How Modernizr Is Included

The usefulness of a responsible approach can be resumed in one question: do you like waiting for several seconds to access a web page? Surely not, and your visitors hate that too. That’s why, if they wait for a long time for the page to be displayed, they won’t come back. And I’m pretty sure you don’t want that. We all love fancy features, but not if they slow down our website too much. The good news is that you can still keep your fancy features, even with a responsible approach. The difference is that you won’t load them the same way.

Let’s discuss a concrete example of a JavaScript file. In a lot of cases, we wait for the page to be loaded before executing the script. In these cases, including the script in the head element is useless because the script is loaded at a very early stage but it’ll wait for the page to be loaded before running. The problem is that if your script is included in the head, the browser will load it before the page itself. This means that if your script is big in size, your visitors have to wait until the script is loaded before they can see the page.

Modernizr has been developed to determine if you can use some recent features, such as CSS transitions or transformations, in a web page. Excluding some special cases, you don’t need these features in order to display something on the screen of the user. There are scripts that must be included in the head tag, but most of them don’t. Modernizr is no exception. In most cases you don’t need to include it in the head and you can include the library right before the end of the body.

Before moving forward, I want to clarify a point: if a web page using Modernizr takes a long time to load, including this library responsibly won’t be enough to improve the performance. Embracing a responsible approach means that you have to think about it each time you want to include a JavaScript file or other potentially big resources. If you optimize the way one resource is included, you won’t necessary see a big difference. However, if you optimize how you include all your resources, the difference can be huge.

Continue reading %How to Use Modernizr Responsibly%

Source: Sitepoint

Experimenting with Object.observe in JavaScript

Object.observe data binding browser support comparison

I recently built a quick prototype to get the classic interactive movie game Night Trap running in the browser. Assets stream from Azure Media Services and play through the open source video.js player as an .mp4. I also converted all of the video to adaptive streaming and am now in the process of using the Azure Media Player. Read my two-part post, Deconstructing Night Trap, for an overview of the process.

In rebuilding Night Trap, I ran into an issue where I needed to listen for an event, specifically when the URL for the video feed changes as a user is viewing a camera in a particular room. For example, I am looking at the kitchen camera and there is nothing going on, and at the 1:20 mark characters are supposed to enter the room. How do I tell the video player that the URL has changed at that time and that it should be playing the new URL I just passed in?

In comes Object.observe to save the day.


What is Object.observe?

In my search for a solution that I could use immediately, I stumbled across this excellent GitHub repo from MaxArt2501. Within it, he wrote a polyfill that allowed me to use Object.observe right now. Perfect!

His description sums up the issue well:

Object.observe is a very nice EcmaScript 7 feature that has landed on Blink-based browsers (Chrome 36+, Opera 23+) in the first part of 2014. Node.js delivers it too in version 0.11.x, and it’s supported by io.js since its first public release.
In short, it’s one of the things web developers wish they had 10-15 years ago: it notifies the application of any changes made to an object, like adding, deleting or updating a property, changing its descriptor and so on. It even supports custom events. Sweet!

The problem is that most browsers still doesn’t support Object.observe. While technically it’s impossible to perfectly replicate the feature’s behaviour, something useful can be done keeping the same API.

If you aren’t familiar with polyfills, they are basically a temporary fix, made with JavaScript, which provides a temporary solution to a feature which may / may not be implemented in the browser at some point in the future. While we’d prefer to have these features of the language built into the browser natively, we also have to understand that it’s a bit of a project to implement these things too, along with the necessity of prioritizing which features get added.

As mentioned above, this is an EcmaScript 7 feature, but we don’t even have EcmaScript 6 (JavaScript 2015) properly supported in all browsers at the moment, so I wasn’t going to hold my breath waiting for this to happen.

Continue reading %Experimenting with Object.observe in JavaScript%

Source: Sitepoint

How to Use Web Fonts in WordPress

Recently, everybody seems to be talking about Lobster. Not the crustaceans from the ocean, but the Web Font. For those who haven’t heard of it, Lobster is a good example of a popular Google Font that is embedded into web pages.

Embedding fonts is not as new as you might think. Way back in 1998, CSS 2 introduced the @font-face rule. This, in theory, enabled designers to download any TrueType or PostScript font to a users computer for display in web pages. Unfortunately, at the time, only Internet Explorer 4 supported the rule. There was widespread fear that fonts that were expensive to licence would be pirated. Today, CSS 3 still doesn’t help with the piracy issue, but all web browsers support the rule. Screen resolutions have improved dramatically since that time too. So, if you haven’t embraced font embedding yet, now is the time to do so.

Current Web Font Options

Before we talk about using web fonts in WordPress, let’s take a step back and look at fonts on the web in general.

The most basic level of support for fonts comes from the operating system that the user is using. This may offer dozens of fonts for a desktop or laptop system to only three fonts on Android.

Unfortunately, this remains a fairly pot luck system. We’re all aware of how poorly Helvetica looks on Windows-based machines when set at 16px and below, and that Arial can look less than fantastic on some older versions of OS X.

Many of these discrepancies have come about because the original Apple Mac operating system was tied to old printing press technology of 72 points per inch. 10 point fonts were thus allocated 10 pixels on the display. At the time, Apple offered vertical (portrait) monitors that were the same size as standard American paper, and a direct one-to-one comparison could be made from the screen to a printed version. Microsoft on the other hand, chose 96 PPI on the basis people would be sitting an additional 1/3 of the distance away from a computer monitor than they would from a printed page. Thus everything was rendered 1/3 larger on a Windows-based computer.

Things have come a long way since the 1990s when these technologies emerged, and we now have a myriad of different screen sizes and resolutions to deal with. Yet, unless you specify a font, the users’ device and browser will still make the choice of font for you.

Another issue is that some organisations limit the fonts on users computers. I once worked at an organisation whose computers only had Georgia and Verdana installed. This was so that letters and emails sent by employees could only be sent using a font that matched the corporate identity.

Continue reading %How to Use Web Fonts in WordPress%

Source: Sitepoint

Fire up Your E-Commerce Site with Solidus


A few days ago Sean Schofield, the CEO of Spree, announced the acquisition of Spree by First Data. It appears that the open source project Spree will no longer be supported.

Solidus is an open source, eCommerce application for high volume retailers. Built with Ruby on Rails, this mountable engine provides a scalable, stable, and highly customizable platform for online commerce. It’s just a continuation (meaning, a fork) of Spree 2.4 without the commercial direction of the newly-acquired Spree Commerce

In this tutorial, we will learn to install Solidus.

NOTE: I am using Ubuntu 14.04 as I write this tutorial. For the sake of readers using Mac, links are added where necessary.

Continue reading %Fire up Your E-Commerce Site with Solidus%

Source: Sitepoint

Switching From Adobe Fireworks To Sketch: Ten Tips And Tricks


Transitions can be painful. It is in our nature to resist change, even when the possibility of doing something new and different may be exciting. Changing your workflow can be a real challenge if you don’t know where to start or understand how to embark on the change.

Switching From Adobe Fireworks To Sketch: 10 Tips And Tricks

I’ve met with many designers (graphic, interaction, UI, etc.) who stick to old software because they are familiar and in their comfort zone, or because they are too scared to take the “leap of faith” and try something new (even when they know their old software does not allow them to work efficiently and effectively enough).

The post Switching From Adobe Fireworks To Sketch: Ten Tips And Tricks appeared first on Smashing Magazine.

Source: Smashing Magazine