public function makeimg()
{
$path_1 = 'uploads/seven.png';
$path_2 = 'http://wx.qlogo.cn/mmopen/PiajxSqBRaEJibOmQsOZ3fUUNscz3v592BKwCjnC3HYHHnMibuQ5pGo1KrsPruYNMmmZKiaKNoV7cp7biciarqWBQreA/0';
if(!file_exists("uploads/wxcode/")) {
mkdir("uploads/wxcode/", 0755, true);
}
$file_name = "uploads/wxcode/".time().".png";
$codeimg = imagecreatefromstring(file_get_contents($path_1));
$src_img = imagecreatefromstring(file_get_contents($path_2));
$w = $h = min(imagesx($src_img), imagesy($src_img));
$newwidth = $newheight = 192;
$img = imagecreatetruecolor($w, $h);
imagesavealpha($img, true);
$bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagefill($img, 0, 0, $bg);
$r = $w / 2;
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$rgbColor = imagecolorat($src_img, $x, $y);
if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
imagesetpixel($img, $x, $y, $rgbColor);
}
}
}
$newimg = imagecreatetruecolor($newwidth, $newheight);
imagesavealpha($newimg, true);
$color = imagecolorallocatealpha($newimg, 255, 255, 255, 127);
//$color = imagecolorallocate($newimg,255,255,255);
imagefill($newimg, 0, 0, $color);
imageColorTransparent($newimg, $color);
imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, imagesx($img), imagesy($img));
imagecopymerge($codeimg, $newimg, 119, 119, 0, 0, imagesx($newimg), imagesy($newimg), 100);
imagepng($codeimg,$file_name);
response_ok($file_name);
}
#PHP# #GD# #小程序码#