PHP development picture watermark tutorial output picture
<?php
/*打开图片*/
//配置图片路径
$src = "https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg";
//获取图片的基本信息
$info=getimagesize($src);
//通过图像的编号来获取图片的类型
$type=image_type_to_extension($info[2],false);
//内存中创建一个和我们图像类型一致的图像
$fun = "imagecreatefrom{$type}";
//把要操作的图片复制到内存中
$image=$fun($src);
/*操作图片*/
//设置水印路径
$image_Mark = "https://img.php.cn/upload/course/000/000/004/5814594e3e7c9278.png";
//获取水印的基本信息
$info2=getimagesize($image_Mark);
//通过水印的图像编号来获取水印的图片类型
$type2=image_type_to_extension($info2[2],false);
//在内存中创建一个和水印图像一致的图像类型
$fun2="imagecreatefrom{$type2}";
//把水印复制到内存中
$water = $fun2($image_Mark);
//合并图片
imagecopymerge($image,$water,60,40,0,0,$info2[0],$info2[1],30);
//销毁水印图片
imagedestroy($water);
/*输出图片*/
header("Content-type:",$info['mime']);
$funs = "image{$type}";
$funs($image);
/*销毁图片*/
imagedestroy($image);
?> header("Content-type:",$info['mime']);
$funs = "image{$type}";
$funs($image);
$funs($image,'FFFF.'.$type);/*销毁图片*/ imagedestroy($image);
Define a variable $funcs to output the image and then destroy the image
The image watermark is added to the image.
Explanation of $info['mime']
If it is written as header('content_type:image/jpeg'), it means that the type can only be the image type, and it can only be It is in jpeg format.
Written as header('content_type:'.$info['mime']), content_type is determined by the uploaded file and is variable (if it is a png image, it is image/png), which is more flexible !
print_r($info); Array ( [0] => 850 [1] => 511 [2] => 3 [3] => width="850" height="511" [bits] => 8 [mime] => image/png )
$info['mime'] refers to the image/png, which is the type of file
new file
<?php
/*打开图片*/
//配置图片路径
$src = "https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg";
//获取图片的基本信息
$info=getimagesize($src);
//通过图像的编号来获取图片的类型
$type=image_type_to_extension($info[2],false);
//内存中创建一个和我们图像类型一致的图像
$fun = "imagecreatefrom{$type}";
//把要操作的图片复制到内存中
$image=$fun($src);
/*操作图片*/
//设置水印路径
$image_Mark = "https://img.php.cn/upload/course/000/000/004/5814594e3e7c9278.png";
//获取水印的基本信息
$info2=getimagesize($image_Mark);
//通过水印的图像编号来获取水印的图片类型
$type2=image_type_to_extension($info2[2],false);
//在内存中创建一个和水印图像一致的图像类型
$fun2="imagecreatefrom{$type2}";
//把水印复制到内存中
$water = $fun2($image_Mark);
//合并图片
imagecopymerge($image,$water,60,40,0,0,$info2[0],$info2[1],30);
//销毁水印图片
imagedestroy($water);
/*输出图片*/
header("Content-type:",$info['mime']);
$funs = "image{$type}";
$funs($image);
/*销毁图片*/
imagedestroy($image);
?>
Preview
Clear
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~ 