如何在Laravel软件包SimpleSoftwareio/Simple-Qrcode中插入QRCode格式的一些文本



我正在使用https://github.com/simplesoftwareio/simple-qrcode在laravel中实现qrcode。

我想用png格式插入qrcode下的一些文本。我怎样才能做到这一点?此软件包支持下载qrcode以png的格式吗?

长时间搜索后。我可以通过此答案从某些文本中创建一个png映像https://stackoverflow.com/a/49704951/8071577,然后由此教程将其保存在文件夹中https://hdttuto.com/article.com/article/article/how-to-to-convert-how-to-convert-how-how-to-convert-how-how-how-how-how-how-how-how-how-Base64至图像和弹药php。然后,我使用合并函数将图像放在QRCode格式png上。这是我的代码。

// 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 = AppUserPet::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(AppUserPet::QRCODE_DIRECTORY.'/'.$pet->code_qr.'.png');
QrCode::format('png')->margin(10)->merge(AppUserPet::TEXTQR_DIRECTORY.'/'.$pet->code_qr.'.jpg', 1, true)->size(200)->generate('hihihi - '.route('pet.detail', ['id' => $pet->code_qr]), $pathDirectory);

最新更新