Text to Image in PHP with GD

This is simple script to demonstrate the capabilities of PHP with the GD library, which provides a lot of image functions that can be useful in many applications. GD provides a rich set of functions. For a complete list of these functions, check the PHP manual.

header('Content-Type: image/png');
// Text to be converted to image
$text = 'Hello World';
// Font to use, give accessible path from script
$font = './arial.ttf';
// Convert HTML entities into ISO-8859-1
$text = html_entity_decode($text,ENT_NOQUOTES, "ISO-8859-1");
// Create the image
$im = imagecreatetruecolor(160, 160);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// Create some colors
imagefilledrectangle($im, 0, 0, 160, 80, $white);
// Add the text
imagettftext($im, 12, 0, 20, 20, $black, $font, $out);

GD can also be used to create and manipulate image files in a variety of different image formats, including GIF, PNG, JPEG, WBMP, and XPM.


  • Though GD supports Unicode text inputs, it doesn’t support complex text rendering
  • Complex Text Rendering is required for properly displaying many language texts, such as the Arabic alphabet and scripts of the Brahmic family, which includes Tamil and many other Indic scripts.

There is a alternative for this using Pango and Cairo in PHP. I’ll post a detailed update on that in my next post.

Using the ‘exclude’ option with ‘tar’

I’m always confused with the use of ‘exclude’ options with ‘tar’. Here I’m sharing a few tips I found online, just in case it might help you. The meanings of –exclude and –exclude-from are always confusing:

  • Use –exclude when files to be excluded are given as a pattern on the command line.
  • Use –exclude-from to introduce the name of a file which contains a list of patterns, one per line; each of these patterns can exclude zero, one, or many files.

When using –exclude=pattern, be sure to quote the pattern parameter, so GNU tar sees wildcard characters like ‘*’.

For example, write:

$ tar -c -f <em>archive.tar</em> --exclude '*.o' <em>directory</em>

tar does not act on a path name explicitly listed on the command line if one of its file name components is excluded. If files that end with ‘*.o’ are excluded when creating an archive, but explicitly name the file ‘dir.o/foo’ after all the options have been listed, ‘dir.o/foo’ will be excluded from the archive.
Only shell syntax, or globbing will work with exclude options in tar. The command might fail if regexp syntax is used to describe files to be excluded in the command.


Being Nice on a Linux Box – Process priority with ‘nice’ & ‘renice’

Problem (I had): Wanted to run a VirtualBox on a RHEL 4.7 Linux server which is shared by someothers. But as some other processes took more CPU, the VirtualBox performance was bad. So I wanted to increase the priority given to VirtualBox.

Solution (I found): VirtualBox can be given higher priority using nice command. Also renice command can be used to change the priority of a running process, which will also be useful.

nice -10 VBoxHeadless

Gives the VBoxHeadless process 1.5 times priority than the normal process, calculated as (20 – -10)/20 = 1.5

nice -20 make

Executes make at maximum priority.

renice +20 2222

Changes the priority of process 2222 to +20 (minimum priority).

renice -10 -p 13013

Changes the priority of a running process by specifying its process ID, where priority can be,

  • 1 to 20 : Runs the specified processes slower than the base priority.
  • 0 : Sets priority of the specified processes to the base scheduling priority.
  • -20 to -1 : Runs the specified processes quicker than the base priority.

References and further reading:

Shell – How to get surrounding lines of grep result?

I'm using grep to search for an error and want to display the surrounding lines also as they contain related information. How to do that?

Using grep -C <# of lines to show above and below> <search> <file>

The following prints the matched line, along with the 5 lines surrounding it.

$ grep -C 5 "search" sample_text

Also we can use grep -A or -B to display number of lines above or below the matched line.

The following prints the matched line, along with the 5 lines after it.

$ grep -A 5 "search" sample_text

The following prints the matched line, along with the 5 lines before it.

$ grep -B 5 "search" sample_text


VLC Media Player says Merry Christmas

VLC Christmas Cap The popular multiplatform media player VLC Media Player says Merry Christmas to all users this festive season by putting a red Christmas hat icon. This is an Easter egg in the latest version of VLC media player, and those who have the updated version will notice this at use.

renjus blog reports that,

If you are a VLC addict then you will have noticed this change as of Midnight 18 December.It seems as the developers from VLC decided to included this Easter egg on their later version 0.9+.

VLC Player for Christmas Image source: jb [Kinnda lazy to take a screenshot :)]