How to add a partially transparent logo to PHP on a QR code

Source: Internet
Author: User
That's the QR code.

Made a square and center transparent, white border picture to embed in the QR code image
But the original center black and white position is completely transparent after the synthesis, such as

How to handle this situation, the code is as follows
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);


Reply to discussion (solution)

This effect?

$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 _q R_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);

Isn't it easier to draw directly on $QR?

Isn't it easier to draw directly on $QR?


is really the above effect, just contact with the PHP drawing, not quite understand


This effect?

$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 _q R_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);



Praise, really is the above effect, just touch PHP drawing, there are many functions do not understand
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.