<?php
            $target_width=640;
            $target_height=1080;
            $hec_width=580;
            $hec_height=840;
            $bigImgPath = 'img/hec.jpg';
            $qCodePath = 'img/jw8.png';
  

            $target_image = imagecreatetruecolor($target_width, $target_height);//设置画布
            $hec_image = imagecreatetruecolor($hec_width, $hec_height);//设置画布
         
            $bg1 = imagecolorallocatealpha($hec_image , 51 , 51 , 51 , 127);//
            imagealphablending($hec_image , true);//关闭混合模式,以便透明颜色能覆盖原画板  
            imagefill($hec_image , 0 , 0 , $bg1);//填充 
            imagesavealpha($hec_image , true);//设置保存PNG时保留透明通道信息
            $bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
            $qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));
       

            $source['size']= getimagesize($bigImgPath); 
            $qCodePath1['size']= getimagesize($qCodePath);
                 // 缩放
            imagecopyresampled($target_image, $bigImg, 0, 0, 0, 0, $target_width, $target_height, $source['size'][0], $source['size'][1]);

              // 缩放
            imagecopyresampled($hec_image, $qCodeImg, 0, 0, 0, 0, $hec_width, $hec_height, $qCodePath1['size'][0], $qCodePath1['size'][1]);
            imagecopy($target_image, $hec_image, 30, 30, 0, 0, $hec_width, $hec_height); 
        header('content-type:image/gif');  //设置gif Image
           imagepng($target_image); 
          
 ?>

图1

php png透明图片合成 

图2

php png透明图片合成

合成效果图

 php png透明图片合成

 

 

相关文章: