PHP development...LOGIN

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


Next Section
<?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); ?>
submitReset Code
ChapterCourseware