Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gdimage output #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

nadenislamarre
Copy link

Signed-off-by: Nicolas Adenis-Lamarre nicolas.adenis.lamarre@gmail.com

Signed-off-by: Nicolas Adenis-Lamarre <nicolas.adenis.lamarre@gmail.com>
@nadenislamarre
Copy link
Author

nadenislamarre commented Nov 21, 2022

maybe the qrPngLogo could be added somewhere too ?
the idea is to produce image with logo.

?php
require_once("phpqrcode/qrlib.php");

//$QR = QRcode::png($_GET["url"], false, QR_ECLEVEL_H, 20, 1, true);
//exit(0);

qrPngLogo($_GET["url"], "logo.jpg", QR_ECLEVEL_H, 20, 1, 4, true);

function qrPngLogo($text, $logopath, $level, $size, $margin, $logo_ratio, $print = false) {
$QR = QRcode::gdimage($text, $level, $size, $margin);

if( ($data = file_get_contents($logopath)) === false)
throw new Exception("unable to read logo");

if( ($logo = imagecreatefromstring($data)) === false)
throw new Exception("unable to read logo");

$QR_width = imagesx($QR);
$QR_height = imagesy($QR);
$logo_width = imagesx($logo);
$logo_height = imagesy($logo);
if($QR_width === false || $QR_height === false || $logo_width === false || $logo_height === false)
throw new Exception("unable to read image size");

$logo_qr_width = $QR_width/$logo_ratio;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;

if(imagecopyresampled($QR, $logo, $QR_width/2-$logo_qr_width/2, $QR_height/2-$logo_qr_height/2, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height) === false)
throw new Exception("unable to write the logo");
ImageDestroy($logo);

if($print) {
header ('Content-Type: image/png');
imagepng($QR);
ImageDestroy($QR);
} else {
return $QR;
}
}
?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant