Posts

Showing posts with the label utility

Creating a Custom Log Helper for the CodeIgniter Framework

Over the past few months, we've been working extensively with the PHP CodeIgniter framework. One thing that consistently slowed me down during debugging was the repetitive process of logging variables. Every time I needed to log a variable, I found myself typing out log_message('error', $your_variable) —a lengthy 18 characters every single time! And that’s just for basic variables. If I wanted to log a boolean, object, or array, the process became even more time-consuming, often requiring additional if statements or extra formatting. To simplify this process, I decided to write a small custom log helper. This helper makes logging easier by automatically handling different variable types, allowing for faster and more efficient debugging. If you’re working with CodeIgniter and find logging as tedious as I did, you might find this helper useful too. <? if ( !function_exists('l') && !function_exists('l2') && !function_exists('ge...

Automatically Rotating Scanned Text Images with Tesseract OCR

Problem If you've ever had a batch of scanned images with text, you know how tedious it can be to manually rotate each one to the correct orientation. This process can be especially frustrating when dealing with a large number of images. Wouldn't it be great if there were a way to automatically rotate these images so that the text is always upright and readable? Solution To solve this problem, I developed a simple script that automatically detects the correct orientation of text in scanned images using Optical Character Recognition (OCR) and dictionary matching. Here's how it works: OCR Parsing with Tesseract : I used Tesseract, a popular open-source OCR engine, to extract text from the images. Tesseract is powerful and versatile, making it an excellent choice for this task. Dictionary Matching : I created a list of the most commonly occurring words in the text. This list acts as a reference to determine the correct orientation. While my example includes only 5-6 words,...