Jump to content

Confused/Baffled


Dysan

Recommended Posts

If the $string variable contains "101010" in the following code, the width of the barcode displayed is larger than if the $string variable contained "111111".

 

But, if "101010" is entered into the textbox displayed on at the following URL, and the "Generate Barcode" button is clicked, the barcode displayed is the same width than if "111111" was entered into the textbox.

 

URL: www.sid6581.net/cs/php-scripts/barcode/

 

The only difference is the barcode display is slightly different, to reflect the diffrent value entered.

 

What needs to be changed in the following code, in order for the bar code to display the same width, regardless of the barcode value. Like it does in the demo found at the above URL?

 

<?php
$rectangle_width = 2;
$rectangle_height = 100;

$image = imagecreatetruecolor(300, 188);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

imagefill($image, 0, 0, $white);
imagerectangle($image, 0, 0, 298, 186, $black);

$find = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*');
$replace = array('1010001110111010', '1110100010101110', '1011100010101110', '1110111000101010', '1010001110101110', '1110100011101010', '1011100011101010', '1010001011101110', '1110100010111010', '1011100010111010', '1000101110111010');

$string = '*111111*';
$textstring = str_replace($find, $replace, $string);

$j = 11;
$sarray = str_split($textstring, 1);
for($i = 0; $i < count($sarray); $i++)
{
    if($sarray[$i] ==  '0')
    {
        imagefilledrectangle($image, $rectangle_width * $j, 150, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $white);
        $j++;
        
    }
    elseif($sarray[$i] ==  '1')
    {
        imagefilledrectangle($image, $rectangle_width * $j, 150, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $black);
        $j++;
    }
} 

imagettftext($image, 10, 0, 120, 170, $black, "Verdana", $string);

header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
?>

Link to comment
https://forums.phpfreaks.com/topic/85382-confusedbaffled/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.