PHP development thumbnail output image
Output image
<?php
/*打开图片*/
$src = "https://img.php.cn/upload/course/000/000/004/5812bd10e70ef729.jpg";
$info = getimagesize($src);
$type = image_type_to_extension($info[2],false);
$fun = "imagecreatefrom{$type}";
$image = $fun($src);
/*操作图片*/
//在内存中建立一个宽300高200的真色彩图片
$image_thumb = imagecreatetruecolor(300,200);
//将原图复制到新建的真色彩图片上,并且按照一定比例压缩(参数1:真色彩图片,参数2:原图,参数3,4,5,6:原图和真色彩图的起始点,参数7,8:原图和真色彩图的结束点,参数9:原图宽,参数10:原图高)
imagecopyresampled($image_thumb,$image,0,0,0,0,300,200,$info[0],$info[1]);
//销毁原始图片
imagedestroy($image);
/*输出图片*/
header("Content-type:".$info['mime']);
$funs = "image{$type}";
$funs($image_thumb);
//保存到硬盘
$funs($image_thumb,"thumb_image.".$type);
/*销毁图片*/
imagedestroy($image_thumb);
?>/*输出图片*/
header("Content-type:".$info['mime']);
$funs = "image{$type}";
$funs($image_thumb);
//保存到硬盘
$funs($image_thumb,"thumb_image.".$type);
/*销毁图片*/
imagedestroy($image_thumb);At this point, the thumbnail creation is completed.
new file
<?php
/*打开图片*/
$src = "https://img.php.cn/upload/course/000/000/004/5812bd10e70ef729.jpg";
$info = getimagesize($src);
$type = image_type_to_extension($info[2],false);
$fun = "imagecreatefrom{$type}";
$image = $fun($src);
/*操作图片*/
//在内存中建立一个宽300高200的真色彩图片
$image_thumb = imagecreatetruecolor(300,200);
//将原图复制到新建的真色彩图片上,并且按照一定比例压缩(参数1:真色彩图片,参数2:原图,参数3,4,5,6:原图和真色彩图的起始点,参数7,8:原图和真色彩图的结束点,参数9:原图宽,参数10:原图高)
imagecopyresampled($image_thumb,$image,0,0,0,0,300,200,$info[0],$info[1]);
//销毁原始图片
imagedestroy($image);
/*输出图片*/
header("Content-type:".$info['mime']);
$funs = "image{$type}";
$funs($image_thumb);
//保存到硬盘
$funs($image_thumb,"thumb_image.".$type);
/*销毁图片*/
imagedestroy($image_thumb);
?>
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~ 