I have a page that mounts a barcode, I want to know how to do it instead of returning an html page, it returns an image.
Example of how my page is:
<?php
$fino = 1;
$largo = 3;
$altura = 50;
$text = null;
$barcodes[0] = '00110';
$barcodes[1] = '10001';
$barcodes[2] = '01001';
$barcodes[3] = '11000';
$barcodes[4] = '00101';
$barcodes[5] = '10100';
$barcodes[6] = '01100';
$barcodes[7] = '00011';
$barcodes[8] = '10010';
$barcodes[9] = '01010';
for ($f1 = 9; $f1 >= 0; $f1--) {
for ($f2 = 9; $f2 >= 0; $f2--) {
$f = ($f1 * 10) + $f2;
$texto = '';
for ($i = 1; $i < 6; $i++) {
$texto .= substr($barcodes[$f1], ($i - 1), 1) . substr($barcodes[$f2], ($i - 1), 1);
}
$barcodes[$f] = $texto;
}
}
$text .= '<img src="../Img/p.gif" style="width: ' . $fino . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img src="../Img/b.gif" style="width: ' . $fino . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img src="../Img/p.gif" style="width: ' . $fino . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img src="../Img/b.gif" style="width: ' . $fino . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img ';
// Recebe os dados
$texto = addslashes(filter_input(INPUT_GET, 'linha', FILTER_SANITIZE_NUMBER_INT));
if ((strlen($texto) % 2) <> 0) {
$texto = '0' . $texto;
}
while (strlen($texto) > 0) {
$i = round(substr($texto, 0, 2));
$texto = substr($texto, strlen($texto) - (strlen($texto) - 2), (strlen($texto) - 2));
if (isset($barcodes[$i])) {
$f = $barcodes[$i];
}
for ($i = 1; $i < 11; $i += 2) {
if (substr($f, ($i - 1), 1) == '0') {
$f1 = $fino;
} else {
$f1 = $largo;
}
$text .= 'src="../Img/p.gif" style="width: ' . $f1 . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img ';
if (substr($f, $i, 1) == '0') {
$f2 = $fino;
} else {
$f2 = $largo;
}
$text .= 'src="../Img/b.gif" style="width: ' . $f2 . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img ';
}
}
$text .= 'src="../Img/p.gif" style="width: ' . $largo . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img src="../Img/b.gif" style="width: ' . $fino . 'px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$text .= '<img src="../Img/p.gif" style="width: 1px; height: ' . $altura . 'px; border: 0; padding: 0; margin: 0;">';
$img = imagecreate(410, 55);
// Transparent background
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
// Red text
$red = imagecolorallocate($img, 255, 0, 0);
imagestring($img, 5, 0, 0, $text, $red);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);