Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

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 [email protected]

Signed-off-by: Nicolas Adenis-Lamarre <[email protected]>
@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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant