Home Tutorial Php Phpgd PHP GD graphical counter

 
 

PHP GD graphical counter
Posted on: November 13, 2009 at 12:00 AM
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

Related Tags for PHP GD graphical counter:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.