php png透明图片合成

博客展示了图1、图2以及合成效果图,与图像处理相关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?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

 

图2

合成效果图

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值