标签:
<?php // Including all required classes require_once(‘class/BCGFontFile.php‘); //引入字体生成文件 require_once(‘class/BCGColor.php‘);//引入背景颜色文件 require_once(‘class/BCGDrawing.php‘);//引入图片生成文件 // Including the barcode technology require_once(‘class/BCGcode39.barcode.php‘);//引入条形码编码规则文件 // Loading Font $font = new BCGFontFile(‘./font/Arial.ttf‘, 18);//引入字体,并设置字号 // Don‘t forget to sanitize user inputs $text = isset($_GET[‘text‘]) ? $_GET[‘text‘] : ‘dsfdfasda‘; //设置条形码的原文本的内容 // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); //设置黑色的rgb 颜色 $color_white = new BCGColor(255, 255, 255);//设置白色的rgb颜色 $drawException = null; try { $code = new BCGcode39(); //创建一个新的对象 $code->setScale(1.4); // Resolution //设置缩放的比例 $code->setThickness(60); // Thickness //设置高度 $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) //设置字体 $code->parse($text); // Text //转换字体 } catch(Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing(‘‘, $color_white);//创建一块画布 if($drawException) { $drawing->drawException($drawException); //假如捕获到错误就输出 } else { $drawing->setBarcode($code); //设置条形码 $drawing->draw();//生成图片 } // Header that says it is an image (remove it if you save the barcode to a file) header(‘Content-Type: image/png‘); //告诉浏览器这是一张png格式的图片 header(‘Content-Disposition: inline; filename="barcode.png"‘); //配置,在行内,设置文件名称 // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); //输出图像是png格式 ?>
标签:
原文地址:http://www.cnblogs.com/leong/p/4279149.html