Share on Google+Share on Google+

PHP GD graphical counter

Ads
This example shows how to make graphical counter in php gd.

<?php

define("C_DIGITS", "images.jpg");

define("DIGIT_WIDTH", 12);

define("DIGIT_HEIGHT", 13);

$number;

settype($number, "string");

$t_digits = strlen($number);

$width = ($t_digits * DIGIT_WIDTH) + 3;

$height = DIGIT_HEIGHT + 3;

$img = imagecreate($width, $height);

$digits = imagecreatefromjpeg(C_DIGITS);

$background = $black = imagecolorallocate($img, 0, 0, 0);

$dest_x_offset = 1;

for($i = 0; $i < $t_digits; $i++) {

$cur_digit = (int)$number[$i];

$digit_offset = (DIGIT_WIDTH * $cur_digit) - 1;

imagecopy($img, $digits,

$dest_x_offset, 1,

$digit_offset,

0,

DIGIT_WIDTH + 1,

DIGIT_HEIGHT + 1);

$dest_x_offset += DIGIT_WIDTH;

}

header("Content-Type: image/jpeg");

imagejpeg($img);

?>

After running the program you will get the following output

Advertisements

Posted on: November 13, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Ads

Advertisement