I'm implementing qrcode in laravel using https://github.com/SimpleSoftwareIO/simple-qrcode this package.
I want to insert some text under the QRCode with PNG format. How can I do that? Did this package support download QRCode in format PNG?
I'm implementing qrcode in laravel using https://github.com/SimpleSoftwareIO/simple-qrcode this package.
I want to insert some text under the QRCode with PNG format. How can I do that? Did this package support download QRCode in format PNG?
After a long time search. I can create an PNG image from some text by this answer https://stackoverflow.com/a/49704951/8071577 and i save it in folder by this tutorial https://hdtuto.com/article/how-to-convert-base64-to-image-and-save-it-using-php. And then i use merge function to put image to QRCode format PNG. This is my code.
// Create image (base64) from some text
$string = ' Your text here ';
$width = 150;
$height = 150;
$im = @imagecreate ($width, $height);
$text_color = imagecolorallocate ($im, 0, 0, 0); //black text
// white background
// $background_color = imagecolorallocate ($im, 255, 255, 255);
// transparent background
$transparent = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $transparent);
imagesavealpha($im, true);
imagestring ($im, $font, 40, 130, $string, $text_color);
ob_start();
imagepng($im);
$imstr = base64_encode(ob_get_clean());
imagedestroy($im);
// Save Image in folder from string base64
$img = 'data:image/png;base64,'.$imstr;
$image_parts = explode(";base64,", $img);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$folderPath = \App\UserPet::TEXTQR_DIRECTORY;
$file = $folderPath . '/' . $pet->code_qr . '.jpg';
// MOve to folder
file_put_contents($file, $image_base64);
// Generate QRCode PNG and save put image above with merge funtion
$pathDirectory = storage_path(\App\UserPet::QRCODE_DIRECTORY.'/'.$pet->code_qr.'.png');
QrCode::format('png')->margin(10)->merge(\App\UserPet::TEXTQR_DIRECTORY.'/'.$pet->code_qr.'.jpg', 1, true)->size(200)->generate('hihihi - '.route('pet.detail', ['id' => $pet->code_qr]), $pathDirectory);