Rumah > pembangunan bahagian belakang > tutorial php > 如何 php 在二维码上添加部分透明的logo

如何 php 在二维码上添加部分透明的logo

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-06-23 13:20:01
asal
1264 orang telah melayarinya

这是用的二维码

做了一张四角和中心透明的、白色边框的图片用来嵌入到二维码图片里
但是合成后原来中心黑白的位置全变成透明,如下图

这种情况如何处理,代码如下
list($qrwidth,$qrheight) = getimagesize($imgs['qrcode']);
list($bowidth,$boheight) = getimagesize($imgs['border']);
$QR = imagecreatefrompng($imgs['qrcode']);
$border = imagecreatefrompng($imgs['border']);
$logo_qr_width = $qrwidth / 5;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
$from_width = ($qrwidth - $logo_qr_width) / 2;
imagesavealpha($border,true);
imagecopyresampled($QR, $border, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $bowidth, $boheight);
Header("Content-type: image/png");
ImagePng($QR);


回复讨论(解决方案)

这个效果?

$QR = imagecreatefrompng('http://img.bbs.csdn.net/upload/201601/04/1451892452_282416.jpg');$border = imagecreatefrompng('http://img.bbs.csdn.net/upload/201601/04/1451892077_864770.png');list($qrwidth, $qrheight) = array(imagesx($QR), imagesy($QR));list($bowidth, $boheight) = array(imagesx($border), imagesy($border));$logo_qr_width = $qrwidth / 5;$scale = $bowidth/$logo_qr_width;$logo_qr_height = $boheight/$scale;$from_width = ($qrwidth - $logo_qr_width) / 2;imagesavealpha($border,true);imagecolortransparent($border, imagecolorat($border, 1, 1));imagecopyresampled($QR, $border, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $bowidth, $boheight);ImagePng($QR);
Salin selepas log masuk
Salin selepas log masuk

其实直接在 $QR 上画图不是更简单?

其实直接在 $QR 上画图不是更简单?


确实是上面的效果,刚接触php的画图,还不太了解


这个效果?

$QR = imagecreatefrompng('http://img.bbs.csdn.net/upload/201601/04/1451892452_282416.jpg');$border = imagecreatefrompng('http://img.bbs.csdn.net/upload/201601/04/1451892077_864770.png');list($qrwidth, $qrheight) = array(imagesx($QR), imagesy($QR));list($bowidth, $boheight) = array(imagesx($border), imagesy($border));$logo_qr_width = $qrwidth / 5;$scale = $bowidth/$logo_qr_width;$logo_qr_height = $boheight/$scale;$from_width = ($qrwidth - $logo_qr_width) / 2;imagesavealpha($border,true);imagecolortransparent($border, imagecolorat($border, 1, 1));imagecopyresampled($QR, $border, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $bowidth, $boheight);ImagePng($QR);
Salin selepas log masuk
Salin selepas log masuk



好评,确实是上面的效果,刚接触php的画图,还有很多函数不太了解
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan