The printQRCode_Doli.php looks like the following:
You can see that we use the library “phpqrcode”
The generation and printing out the QR-Code is finally done in “QRCode.php”.
<?php
// file: printQRCode_Doli.php
// some includes
include('phpqrcode/qrlib.php');
include('QRCode.php');
if(isset($_GET['pos1'])) {
$pos1 = $_GET['pos1'];
if(empty($pos1)) {
$pos1=' ';
}
}else{
$pos1='';
}
if(isset($_GET['pos2'])) {
$pos2 = $_GET['pos2'];
if(empty($pos2)) {
$pos2=' ';
}
}else{
$pos2='';
}
if(isset($_GET['pos3'])) {
$pos3 = $_GET['pos3'];
if(empty($pos3)) {
$pos3=' ';
}
}else{
$pos3='';
}
if(isset($_GET['pos4'])) {
$pos4 = $_GET['pos4'];
if(empty($pos4)) {
$pos4=' ';
}
}else{
$pos4=' ';
}
if(isset($_GET['typ'])) {
$type = $_GET['typ'];
if(empty($type)) {
$type=' ';
}
}else{
$type='';
}
$ret = $_GET['ret'];
file_put_contents('/tmp/qrcode.log', $pos1."|".$pos2."|".$pos3."|".$pos4."|".$type."|".$ret."\n", FILE_APPEND);
printQRCodeDolibarr($pos1,$pos2,$pos3,$pos4,$type,$ret);
exit;
?>
The file QRCode.php looks like:
(you can modify the $codeContents to link to other pages in Dolibarr, but we decided that these links are usefull. In case of other links you have to modify/reference the proper ID.)
BTW: You can see the resulting printed labels on my earlier post. If you use another label-printer you have to adapt to your needs.
<?
function printQRCodeDolibarr($pos1,$pos2,$pos3,$pos4,$type,$ret)
{
header('Content-Type: text/html; charset=utf-8');
$tempDir = "temp/";
switch ($type) {
case 'card':
# We still have an intermediate step to correctly resolve "old" QR-Codes in our old read-only DB.
# This is done using "sys=doli", which the old QR-Codes don't have.
# same on case 'charge'
# $codeContents = "http://<our_url>/type.php?id=".urlencode($ret)."&sys=doli";
# gibt ID als Zielwert
$codeContents = "http://<your_dolibarr_url>/product/stock/productlot_card.php?id=".urlencode($ret);
break;
case 'charge':
# $codeContents = "http://<our_url>/part.php?id=".urlencode($ret)."&sys=doli";
# gibt ID als Zielwert
$codeContents = "http://<your_dolibarr_url>/product/card.php?id=".urlencode($ret);
break;
}
#echo $codeContents;
#echo "<br>";
// we need to generate filename somehow,
// with md5 or with database ID used to obtains $codeContents...
$QRfileName = 'qrcode_'.md5($codeContents).'.png';
$fileName = 'qrcodeT_'.md5($codeContents).'.png';
$pngAbsoluteFilePath = $tempDir.$fileName;
$QRAbsoluteFilePath = $tempDir.$QRfileName;
$urlRelativeFilePathQR = 'temp/'.$QRfileName;
$urlRelativeFilePath = 'temp/'.$fileName;
// generating
QRcode::png($codeContents, $QRAbsoluteFilePath);
echo 'Server PNG File: '.$pngAbsoluteFilePath;
echo '<hr />';
// displaying
echo '<img src="'.$urlRelativeFilePathQR.'" />';
$im = imagecreatefrompng($QRAbsoluteFilePath);
//imagesavealpha($im, true); // important to keep the png's transparency
if(!$im) {
die("im is null");
}
$black = imagecolorallocate($im, 0, 0, 0);
list($width, $height) = getimagesize($QRAbsoluteFilePath);
$QL700width = 756;
$largeQRpercentage = 0.5;
$smallQRpercentage = 0.25;
$heightLargerPercentage = 1.1;
$newheight = $heightLargerPercentage*$height*$QL700width/$width*$largeQRpercentage ; // the height of the image
$font = 6; // font size
$leftTextPos = 10; // left position text
$newImage = imagecreate($QL700width,$newheight);
$QLImage = imagecreatetruecolor($QL700width,$newheight);
imagecopyresampled($newImage,$im,0,10,0,0,$QL700width,$newheight/$heightLargerPercentage,$width/$largeQRpercentage,$height);
imagecopyresampled($newImage,$im,$largeQRpercentage*$QL700width,20,0,0,$QL700width,$newheight/$heightLargerPercentage,$width/$smallQRpercentage,$height*$largeQRpercentage/$smallQRpercentage);
imagecopyresampled($newImage,$im,($largeQRpercentage + $smallQRpercentage)*$QL700width,20,0,0,$QL700width,$newheight/$heightLargerPercentage,$width/$smallQRpercentage,$height*$largeQRpercentage/$smallQRpercentage);
#-------------------------------------------------------------
$label = $pos1;
$labelfont = 4;
$labelfont_large = 4;
// pixel-width of label
$txtsz = imagefontwidth($labelfont) * strlen($label);
$txtsz_large = imagefontwidth($labelfont_large) * strlen($label);
// pixel-height of label
$txtht = imagefontheight($labelfont);
$txtht_large = imagefontheight($labelfont_large);
$labelimage = imagecreate($txtsz,$txtht);
$labelimage_large = imagecreate($txtsz_large,$txtht_large);
$white = imagecolorallocate($labelimage, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($labelimage, 0x00, 0x00, 0x00);
$white = imagecolorallocate($labelimage_large, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($labelimage_large, 0x00, 0x00, 0x00);
imagestring($labelimage, $labelfont_large, 0, 0, $label , $black);
imagecopyresampled($newImage,$labelimage,40,0,0,0,3*$txtsz_large, 3*$txtht_large,$txtsz_large, $txtht_large);
imagestring($labelimage, $labelfont, 0, 0, $label , $black);
$labelimage1 = imagerotate($labelimage, -90, $white);
imagecopyresampled($newImage,$labelimage1,$largeQRpercentage*$QL700width-10,40,0,0,2*$txtht, 0.8*$smallQRpercentage*$QL700width,$txtht, $txtsz);
imagecopyresampled($newImage,$labelimage1,($largeQRpercentage + $smallQRpercentage)*$QL700width-10,40,0,0,2*$txtht, 0.8*$smallQRpercentage*$QL700width,$txtht, $txtsz);
#-------------------------------------------------------------
$label = "ID: ".$pos2;
$txtsz = imagefontwidth($labelfont) * strlen($label);
$txtht = imagefontheight($labelfont);
$labelinfo = imagecreate($txtsz,$txtht);
$white = imagecolorallocate($labelinfo, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($labelinfo, 0x00, 0x00, 0x00);
imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
imagecopyresampled($newImage,$labelinfo,$largeQRpercentage*$QL700width-10,$smallQRpercentage*$QL700width+5,0,0,3*$txtsz, 3*$txtht,$txtsz, $txtht);
#-------------------------------------------------------------
$label = $pos3;
$labelfont = 7;
$labelfont_large = 6;
$txtsz = imagefontwidth($labelfont) * strlen($label);
$txtht = imagefontheight($labelfont);
$labelinfo = imagecreate($txtsz,$txtht);
$white = imagecolorallocate($labelinfo, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($labelinfo, 0x00, 0x00, 0x00);
// imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
// changed to TrueType-Font for correct display of german umlauts
$font = '/usr/share/fonts/truetype/droid/DroidSans.ttf';
imagettftext($labelinfo, $labelfont, 0, 0, 10, $black, $font, $label);
// imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
imagecopyresampled($newImage,$labelinfo,$largeQRpercentage*$QL700width-10,$smallQRpercentage*$QL700width+50,0,0,2*$txtsz, 3*$txtht,$txtsz, $txtht);
#-------------------------------------------------------------
$label = $pos4;
$labelfont = 2;
$labelfont_large = 2;
$txtsz = imagefontwidth($labelfont) * strlen($label);
$txtht = imagefontheight($labelfont);
$labelinfo = imagecreate($txtsz,$txtht);
$white = imagecolorallocate($labelinfo, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($labelinfo, 0x00, 0x00, 0x00);
imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
imagecopyresampled($newImage,$labelinfo,$largeQRpercentage*$QL700width-10,$smallQRpercentage*$QL700width+90,0,0,2*$txtsz, 3*$txtht,$txtsz, $txtht);
imagepng($newImage, $pngAbsoluteFilePath, 0);
imagedestroy($im);
imagedestroy($labelimage1);
imagedestroy($labelinfo);
imagedestroy($labelimage);
echo '<img src="'.$urlRelativeFilePath.'" />';
// printing to QL-700
shell_exec("lp -d QL-700 -o orientation-requested=6 ".$pngAbsoluteFilePath);
}
?>