装逼图片旋转合成demo

测试背景 bg.jpg

测试图片 a.jpg

结果示例

代码demo

 1 <?php
 2 
 3 $bgImgFileName = 'bg.jpg';
 4 $a = 'a.jpg';
 5 
 6 // 初始化
 7 $src = imagecreatefromjpeg($a);
 8 list ($w, $h) = getimagesize($a);
 9 
10 // 创建画布
11 $image = imagecreatetruecolor($w, $h);
12 $bgcolor = imagecolorallocatealpha($image, 255, 255, 255, 127);//拾取一个完全透明的颜色,不要用imagecolorallocate拾色
13 imagealphablending($image , false);//关闭混合模式,以便透明颜色能覆盖原画板
14 imagefill($image , 0 , 0 , $bgcolor);//填充
15 imagesavealpha($image , true);
16 
17 // 载入小图
18 imagecopyresampled($image, $src, 0, 0, 0, 0, $w, $h, $w, $h);
19 imagedestroy($src);
20 
21 // 旋转
22 $white = imagecolorallocatealpha($image, 255, 255, 255, 127);
23 $image = imagerotate($image, 30, $white);
24 
25 // 存储临时文件
26 $b = 'b.png';
27 imagepng($image, $b);
28 imagedestroy($image);
29 list ($w, $h) = getimagesize($b);
30 
31 // 打水印
32 $bg = imagecreatefromjpeg($bgImgFileName);
33 $image = imagecreatefrompng($b);
34 imagecopyresampled($bg, $image, 50, 50, 0, 0, $w, $h, $w, $h);
35 imagedestroy($image);
36 
37 // 输出
38 header('Content-Type: image/jpg');
39 imagejpeg($bg);
40 imagedestroy($bg);

 

posted @ 2017-03-20 20:15  andy_chan  阅读(870)  评论(0编辑  收藏  举报