php生成二维码+合并活动图片

2021-08-26  本文已影响0人  风度翩翩的程序猿
 $errorCorrectionLevel = 'L';    //容错级别
        $matrixPointSize = 5;           //生成图片大小
        //生成二维码图片
        $url = $this->user_id ;
        $filename = $this->fileName();
        QRcode::png($url, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
        
        $x = 420;
        $y = 660;
        //合成带logo的二维码图片跟 模板图片--------------start
        $path_1 = './upload/haibao.png';
        $path_2 = base_url() . $filename;
        $image_1 = imagecreatefrompng($path_1);
        $image_2 = imagecreatefrompng($path_2);
        $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
        $color = imagecolorallocate($image_3, 255, 255, 255);
        imagefill($image_3, 0, 0, $color);
        imageColorTransparent($image_3, $color);
        imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));

        imagecopymerge($image_3, $image_2, $x, $y, 0, 0, imagesx($image_2), imagesy($image_2), 100);
        //合成带logo的二维码图片跟 模板图片--------------end

        //输出到本地文件夹
        $file = md5(basename($path_1));
        $EchoPath = './upload/' . $file . '.png';
        imagepng($image_3, $EchoPath);
        imagedestroy($image_3);
        //返回生成的路径
        return $this->json_data(array('st' => 1, 'data' => base_url().$EchoPath));
上一篇下一篇

猜你喜欢

热点阅读