vizon
vizon

Reputation: 363

Adding text to php generated barcode image

I currently am using a script I have found online to generate barcodes for my company. I have modified it a bit to allow the barcode to expand horizontally. The only thing I am lacking is the text the barcode is generating.

I would like the text centered underneath the barcode in a justifiable font size to the barcode.

Here is my barcode script http://pastebin.com/wvTyxQrW

To generate you just go to barcode.php?text=1o2020p1 for example. I just wanted to have that text in the image below the barcode centered. I am just not proefficient enough with image manipulation to do this, it would take me hours.

Thank you for your suggestions / help!

Upvotes: 1

Views: 5393

Answers (1)

air4x
air4x

Reputation: 5683

Replace

  $image = imagecreate($img_width, $img_height);

with

  $image = imagecreate($img_width, $img_height + 20);

And add the following code above // Draw barcode to the screen

if (!empty($_GET['text'])) {
  imagestring($image, 5, 4, $img_height, $_GET['text'], $black);
}

Upvotes: 2

Related Questions