The Code is as follows {code ...}
The Code is as follows:
Include_once WEB_ROOT_PATH. '/classes/phpqrcode. php '; // set it to writable location, a place for temp generated PNG files $ PNG_TEMP_DIR = WEB_ROOT_PATH.DIRECTORY_SEPARATOR. 'usertgcache '. DIRECTORY_SEPARATOR; // html PNG location prefix $ PNG_WEB_DIR = '/userTgCache/'; if (! File_exists ($ PNG_TEMP_DIR) mkdir ($ PNG_TEMP_DIR); $ filename = comment'; $ errorCorrectionLevel = 'H'; $ matrixPointSize = 10; QRcode: png (" http://wwwww.xxxx.com/weixin/testXXXX ", $ Filename, $ errorCorrectionLevel, $ matrixPointSize, 2); $ QR = $ filename; $ logo =" http://wx.qlogo.cn/mmopen/LIUI5tJGiauCMgcRkLbYk7VfUaTdzcbTiaASdCMKj1rFicYTPyL0qibONtUuF9MQmpfRvABlPqJ2xsUbiaSL0q3t6iaF357Vg1PW7U/0 "; If ($ logo! = FALSE) {$ QR = imagecreatefromstring (file_get_contents ($ QR); $ logo = imagecreatefromstring (file_get_contents ($ logo); $ QR_width = imagesx ($ QR ); // QR code Image Width $ QR_height = imagesy ($ QR); // QR code Image Height $ logo_width = imagesx ($ logo ); // logo image width $ logo_height = imagesy ($ logo); // logo image height $ logo_qr_width = $ QR_width/2.5; $ scale = $ logo_width/$ logo_qr_width; $ logo_qr_height = $ logo_height/$ scale; $ from_width = ($ QR_width-$ logo_qr_width)/2; // re-combine the image and resize imagecopyresampled ($ QR, $ logo, $ from_width, $ from_width, 0, 0, $ logo_qr_width, $ logo_qr_height, $ logo_width, $ logo_height);} // display generated file imagepng ($ QR, $ filename); echo'
';
Reply content:
The Code is as follows:
Include_once WEB_ROOT_PATH. '/classes/phpqrcode. php '; // set it to writable location, a place for temp generated PNG files $ PNG_TEMP_DIR = WEB_ROOT_PATH.DIRECTORY_SEPARATOR. 'usertgcache '. DIRECTORY_SEPARATOR; // html PNG location prefix $ PNG_WEB_DIR = '/userTgCache/'; if (! File_exists ($ PNG_TEMP_DIR) mkdir ($ PNG_TEMP_DIR); $ filename = comment'; $ errorCorrectionLevel = 'H'; $ matrixPointSize = 10; QRcode: png (" http://wwwww.xxxx.com/weixin/testXXXX ", $ Filename, $ errorCorrectionLevel, $ matrixPointSize, 2); $ QR = $ filename; $ logo =" http://wx.qlogo.cn/mmopen/LIUI5tJGiauCMgcRkLbYk7VfUaTdzcbTiaASdCMKj1rFicYTPyL0qibONtUuF9MQmpfRvABlPqJ2xsUbiaSL0q3t6iaF357Vg1PW7U/0 "; If ($ logo! = FALSE) {$ QR = imagecreatefromstring (file_get_contents ($ QR); $ logo = imagecreatefromstring (file_get_contents ($ logo); $ QR_width = imagesx ($ QR ); // QR code Image Width $ QR_height = imagesy ($ QR); // QR code Image Height $ logo_width = imagesx ($ logo ); // logo image width $ logo_height = imagesy ($ logo); // logo image height $ logo_qr_width = $ QR_width/2.5; $ scale = $ logo_width/$ logo_qr_width; $ logo_qr_height = $ logo_height/$ scale; $ from_width = ($ QR_width-$ logo_qr_width)/2; // re-combine the image and resize imagecopyresampled ($ QR, $ logo, $ from_width, $ from_width, 0, 0, $ logo_qr_width, $ logo_qr_height, $ logo_width, $ logo_height);} // display generated file imagepng ($ QR, $ filename); echo'
';
Because the remote image you obtain with a url is a jpeg image. That is, the image of truecolor. While png is a so-called palette image,
The logo must be converted into a color palette before color information is not lost during copy.
The Code is as follows:
$ Logo = imagecreatefromstring (file_get_contents ($ logo ));
If (imageistruecolor ($ logo) imagetruecolortopalette ($ logo, false, 65535); // Add this.