/**
* 128 条形码
* @param $content
* @param $path
* @param $scale
* @param $thickness
* @throws \BCGDrawException
*/
public function create_barcode2($content,$path,$scale,$thickness){
//根据运单号生成条形码
$color_black = new \BCGColor(0, 0, 0);
$color_white = new \BCGColor(255, 255, 255);
$drawException = null;
try
{
$code = new \BCGcode128();
$code->setScale($scale);
$code->setThickness($thickness); // 条形码的厚度
$code->setForegroundColor($color_black); // 条形码颜色
$code->setBackgroundColor($color_white); // 空白间隙颜色
// $code->setFont($font); //
$code->parse($content); // 条形码需要的数据内容
}
catch(\Exception $exception)
{
$drawException = $exception;
}
//根据以上条件绘制条形码
$drawing = new \BCGDrawing($path, $color_white);
if($drawException) {
$drawing->drawException($drawException);
}else{
$drawing->setBarcode($code);
$drawing->draw();
}
// 生成PNG格式的图片
header('Content-Type: image/jpeg');
// header('Content-Disposition:attachment; filename="barcode.png"'); //自动下载
$drawing->finish(\BCGDrawing::IMG_FORMAT_JPEG);
//$path = $this->create_barcode($content['yundanhao']);
}
public function print_label_code1(){
$id = $this->request->get('id');
$into_store_goods =Db::table('wh_into_store_goods')->where('id',$id)->find();
$im = imagecreatetruecolor(600,180); // 设置画布/
$font= EXTEND_PATH.'/CreateImg/hanwenziti/fangzhengheiti.ttf';
$bgColor = imagecolorallocate($im, 255, 255, 255); // 颜色
imagefill($im,0,0,$bgColor);
$blacka = imagecolorallocate($im, 0, 0, 0); // 颜色
$path1 = ROOT_PATH .'/public/uploads/images/'.create_guid().'no_1.jpg';
$this->create_barcode2($into_store_goods['label_code'],$path1,2,25);
$src_img1 = imagecreatefromjpeg($path1);
$src_w1 = imagesx($src_img1);
$src_h1 = imagesy($src_img1);
$image1 = file_get_contents($path1);
$images1 = substr_replace($image1,pack("Cnn",0x01,300,300),13,5);
file_put_contents($path1,$images1);
imagecopy($im,$src_img1,80,110,0,0,$src_w1,$src_h1);
$path2 = ROOT_PATH .'/public/uploads/images/'.create_guid().'no_2.jpg';
$this->create_barcode2( str_replace(' ', '',$into_store_goods['sku_code']),$path2,1,50);
$src_img2 = imagecreatefromjpeg($path2);
$src_w2 = imagesx($src_img2);
$src_h2 = imagesy($src_img2);
$image2 = file_get_contents($path2);
$images2 = substr_replace($image2,pack("Cnn",0x01,300,300),13,5);
file_put_contents($path2,$images2);
imagecopy($im,$src_img2,80,20,0,0,$src_w2,$src_h2);
$path44 = '/uploads/images/'.create_guid().'no_4.jpg';
$path4 = ROOT_PATH .'/public'.$path44;
imagejpeg($im, $path4);
$image4 = file_get_contents($path4);
$images4 = substr_replace($image4,pack("Cnn",0x01,300,300),13,5);
file_put_contents($path4,$images4);
imagedestroy($im); // 销毁图片
unlink($path1);
unlink($path2);
$this->assign("path",$path44);
$this->view->engine->layout(false);
return $this->fetch("img_large_no");
}
<script src="__CDN__/assets/js/html5shiv.js"></script>
<script src="__CDN__/assets/js/jquery.jqprint-0.3.js"></script>
<script src="__CDN__/assets/js/jquery.min.js?v={:config('asset_version')}"></script>
<script src="__CDN__/assets/js/jquery.PrintArea.js?v={:config('asset_version')}"></script>
<body>
<div align="center">
<div><button type="button" id="button" name="print" class="btn btn-minw btn-primary" style=" margin-top: 60px; margin-bottom: 60px;
width: 109px;
height: 55px;"><b><h4>打印</h4></b></button></div>
<div id="img_content">
<img src="{$path}" style="width:600px; height:180px"></div>
</div>
<input type="hidden" id ="path" value="{$path}"/>
</body>
<script>
$("#button").click(function(){
//$("#img_content").printArea();
$("#button").attr("style","display:none");
window.print();
setTimeout("",0);
var path = $("#path").val();
$.ajax({
url: "{:url('deletepath')}",
type: "post",
data: {'path': path},
dataType: "json",
success: function (result) {
if(result.code == 1){
window.opener=null;
window.open('','_self');
window.close();
}
}
})
})
</script>
|