I have been using your code successfully for quite some time now. However I have a problem with producing the same(or similar) QR code multiple times. It seems that when I run the code once it successfully saves the QR code to a file. The second time I run the code with with same parameters (except the filename which I change by augmenting the end with '-1.jpg', '-2.jpg', etc.) it will produce the same code successfully again. However, if the same code is run three or more times it will not produce a QR code and save it to a file.
The contents of the QR code is a url which is consistent each time I run the code. I tried to change the url by passing different variables to the url each time I ran the code such as '?uid=45' but this did not resolve the problem.
The purpose of my php code is to add a QR code to a coupon. In some cases a business who orders a coupon from us does not mind for a client to download the same coupon multiple times. Here's where the problems occurs; when a client wants to download the same coupon three times or more.
What change can I make so that the php code will produce a QR code having the same url for content no matter how many times the code is run? Here is my code:
<?php
//qrcode generator
include('qrcode/qrlib.php');
// save QR codes to server with coupon
$tempDir = "images/avatars/buscredits/coupons/";
$codeContents = "www.whosyourbrother.org/verifyoffer.php?bid=";.$busid."&offer=".$adnum."&mid=3".$userid;
$fileNameWO = md5($codeContents);
$fileName = $fileNameWO.'.jpg';
$pngAbsoluteFilePath = $tempDir.$fileName;
//if file exist alter name with hypen and increasing number
/=================================================
Filename Change Code Goes Here
=================================================/
//record coupon instance in database
$couponid = $dt->recordCoupon($busid, $userid, $adnum, $fileName);
//generate QR Code and merge with coupon
if (!file_exists($pngAbsoluteFilePath)) {
define('IMAGE_WIDTH',285);
define('IMAGE_HEIGHT',285);
QRcode::png($codeContents, $pngAbsoluteFilePath);
//Merge qrcode with coupon
$srcFile = "images/avatars/buscredits/buscoupons/".$buscoupon;
$qrcodePNG = "images/avatars/buscredits/coupons/".$fileName;
//create copy of coupon and save
$dest = imagecreatetruecolor(718, 1052);
$src = imagecreatefromjpeg($srcFile);
imagecopyresampled($dest, $src, 0, 0, 0, 0, 718, 1052, 718, 1052);
//merge QR code with Coupon
$src2 = imagecreatefrompng($qrcodePNG);
imagecopymerge ($dest, $src2, 217, 687, 0, 0, 285, 285, 100);
//Save coupon with Qr code to file
imagejpeg($dest,$qrcodePNG);
}
?>
Thanks For Your Help,
Wade Redcross
Hi,
(regarding your priv msg - i am not notified about tickets/request, please use e-mail provided by project website to get support, and - as for many other open source projects - it may take a while to get responce since i do it in spare time)
$log = ob_get_contents(); ob_end_clean(); and saving $log to some file with file_put_contents. What the log says?
write me an email how it going / for further questions (deltalab@poczta.fm)
Regards,
Dominik