Home  >  Article  >  Backend Development  >  009-Generate watermark image + generate thumbnail (PHP)

009-Generate watermark image + generate thumbnail (PHP)

不言
不言Original
2018-04-08 14:56:151105browse

This article introduces the generation of watermark images and thumbnails (PHP). Now I share it with everyone. Friends in need can take a look.


<?php

/**
 * 生成水印图片
 */
//1.获取图片资源
$big = imagecreatefromjpeg(&#39;./kaola.jpg&#39;);  //大图
$small = imagecreatefrompng(&#39;./t1.png&#39;);    //水印图

//2.获取图像大小
list($bw , $bh) = getimagesize(&#39;./kaola.jpg&#39;);
list($w , $h) = getimagesize(&#39;./t1.png&#39;);

//imagecopymerge(dst_im, src_im, dst_x, dst_y, src_x, src_y, src_w, src_h, pct)
//imagecopymerge("目标图","水印图","目标图的x坐标","y坐标","水印图的x","y","宽","高","透明度");
imagecopymerge($big, $small, $bw-$w, $bh-$h, 0, 0, $w, $h, 40);

imagepng($big , &#39;t4.png&#39;);

imagedestroy($big);
imagedestroy($small);


##################################################################################

/**
 * 生成缩略图
 */
$big = imagecreatefromjpeg(&#39;./kaola.jpg&#39;);
list($w , $h) = getimagesize(&#39;./kaola.jpg&#39;);

//创建小画布
$small = imagecreatetruecolor($w/2, $h/2);

//拷贝图像并修改大小
//imagecopyresampled(dst_image, src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
imagecopyresampled($small, $big, 0, 0, 0, 0, $w/2, $h/2, $w, $h);

imagepng($small , &#39;./t6.png&#39;);

imagedestroy($big);
imagedestroy($small);

?>


Function encapsulation

https://blog.csdn.net/liguanjie8/article/details/79835373

Related recommendations:

008-php generates a random verification code

007-PHP GD drawing process

The above is the detailed content of 009-Generate watermark image + generate thumbnail (PHP). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn