Home Tutorial Php Phpgd PHP GD graphical counter

 
 

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

Advertisement

Related Tags for PHP GD graphical counter:


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.

Posted on: November 13, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com