$_REQUEST['code'] = ""; } switch (strtoupper($_REQUEST['type'])) { case "I25": $obj = new I25Object($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['style'], $_REQUEST['code']); break; case "C128A": $obj = new C128AObject($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['style'], $_REQUEST['code']); break; case "C128B": $obj = new C128BObject($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['style'], $_REQUEST['code']); break; case "C128C": $obj = new C128CObject($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['style'], $_REQUEST['code']); break; case "C39": default: $obj = new C39Object($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['style'], $_REQUEST['code']); break; } if ($obj) { $obj->SetFont($_REQUEST['font']); $obj->DrawObject($_REQUEST['xres']); $obj->FlushObject(); $obj->DestroyObject(); unset($obj); /* clean */ } //============================================================+ // END OF FILE //============================================================+
function DrawBarcode($cb, $x, $y, $w, $h, $type = '') { $type = strToLower($type); $len = strlen($cb); // calcule la largeur du code barre en pixels switch ($type) { case 'c128a': case 'c128b': case 'c128c': $width = (35 + $len * 11) * $this->cbXRes; break; case 'i25': $width = (8 + $len * 7) * $this->cbXRes; break; case 'c39': default: $width = (($len + 2) * 12 + $len + 1) * $this->cbXRes; break; } // calcule la hauteur en pixels à partir de la largeur $height = $width * $h / $w; // crée le code barre switch ($type) { case 'c128a': $cbi = new C128AObject($width, $height, $this->cbStyle, "{$cb}"); break; case 'c128b': $cbi = new C128BObject($width, $height, $this->cbStyle, "{$cb}"); break; case 'c128c': $cbi = new C128CObject($width, $height, $this->cbStyle, "{$cb}"); break; case 'i25': $cbi = new I25Object($width, $height, $this->cbStyle, "{$cb}"); break; case 'c39': default: $cbi = new C39Object($width, $height, $this->cbStyle, "{$cb}"); break; } // dessine et incorpore au pdf. $cbi->SetFont($this->cbFontSize); $cbi->DrawObject($this->cbXRes); $filename = FPDF_CB_TEMPPATH . "cb" . time() . $cb; $cbi->SaveTo($filename); $cbi->DestroyObject(); $this->Image($filename, $x, $y, $w, $h, "png"); unlink($filename); }
/** * Print Barcode. * @param int $x x position in user units * @param int $y y position in user units * @param int $w width in user units * @param int $h height position in user units * @param string $type type of barcode (I25, C128A, C128B, C128C, C39) * @param string $style barcode style * @param string $font font for text * @param int $xres x resolution * @param string $code code to print */ function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) { require_once dirname(__FILE__) . "/barcode/barcode.php"; require_once dirname(__FILE__) . "/barcode/i25object.php"; require_once dirname(__FILE__) . "/barcode/c39object.php"; require_once dirname(__FILE__) . "/barcode/c128aobject.php"; require_once dirname(__FILE__) . "/barcode/c128bobject.php"; require_once dirname(__FILE__) . "/barcode/c128cobject.php"; if (empty($code)) { return; } if (empty($style)) { $style = BCS_ALIGN_LEFT; $style |= BCS_IMAGE_PNG; $style |= BCS_TRANSPARENT; //$style |= BCS_BORDER; //$style |= BCS_DRAW_TEXT; //$style |= BCS_STRETCH_TEXT; //$style |= BCS_REVERSE_COLOR; } if (empty($font)) { $font = BCD_DEFAULT_FONT; } if (empty($xres)) { $xres = BCD_DEFAULT_XRES; } $scale_factor = 1.5 * $xres * $this->k; $bc_w = round($w * $scale_factor); //width in points $bc_h = round($h * $scale_factor); //height in points switch (strtoupper($type)) { case "I25": $obj = new I25Object($bc_w, $bc_h, $style, $code); break; case "C128A": $obj = new C128AObject($bc_w, $bc_h, $style, $code); break; default: case "C128B": $obj = new C128BObject($bc_w, $bc_h, $style, $code); break; case "C128C": $obj = new C128CObject($bc_w, $bc_h, $style, $code); break; case "C39": $obj = new C39Object($bc_w, $bc_h, $style, $code); break; } $obj->SetFont($font); $obj->DrawObject($xres); //use a temporary file.... $tmpName = tempnam(K_PATH_CACHE, 'img'); imagepng($obj->getImage(), $tmpName); $this->Image($tmpName, $x, $y, $w, $h, 'png'); $obj->DestroyObject(); unset($obj); unlink($tmpName); }