/    Sign up×
Community /Pin to ProfileBookmark

Code Differences

Whats the difference between the code contained in this post, and the code posted in the second? – The second creates barcodes that can be scanned using a barcode scanner, well as the first block of code doesn’t. Why is this? What has the 2nd block of code got what the 1st hasn’t?

[B]FIRST BLOCK[/B]

[CODE]<?php
$rectangle_width = 2;
$rectangle_height = 20;

$image = imagecreatetruecolor(500, 182);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $white);

$find = array(‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘*’);
$replace = array(‘00110000’, ‘00110001’, ‘00110010’, ‘00110011’, ‘00110100’, ‘00110101’, ‘00110110’, ‘00110111’, ‘00111000’, ‘00111001’, ‘00101010’);

$string = ‘*1101*’;
$textstring = str_replace($find, $replace, $string);

$j = 0;
$sarray = str_split($textstring, 1);
for($i = 0; $i < count($sarray); $i++)
{
if($sarray[$i] == ‘0’)
{
imagefilledrectangle($image, $rectangle_width * $j, 0, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $white);
$j++;

}
elseif($sarray[$i] == ‘1’)
{
imagefilledrectangle($image, $rectangle_width * $j, 0, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $black);
$j++;
}
}

header(“Content-type: image/jpeg”);
imagejpeg($image);
imagedestroy($image);
?>[/CODE]

to post a comment
PHP

1 Comments(s)

×

Success!

Help @Dysan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...