当前位置:首页 > PHP > 正文内容

PHP生成缩略图

高老师9年前 (2017-07-02)PHP1871
//参数1  文件名    参数2  缩放比例
 function   _thumb($_filename,$_percent){
  
ob_clean();
//生成png标头文件
header('Content-type:image/png');
 
$_n=explode('.', $_filename);
 
//获取文件的信息,宽和高
list($_width,$_height)=getimagesize($_filename);
 
//生成缩略后的大小
$_new_width=$_width*$_percent;
$_new_height=$_height*$_percent;
 
 
//按照新的大小创建微缩画布
$_new_image=imagecreatetruecolor($_new_width, $_new_height);
 
//按照已经有的图片创建一个画布[按照图片类型]
switch($_n[1]){
case 'jpg':$_image=imagecreatefromjpeg($_filename);
    break;
case 'png':$_image=imagecreatefrompng($_filename);
    break; 
case 'gif':$_image=imagecreatefromgif($_filename);
    break; 
}
 
//将原来的图复制到新的图片上
imagecopyresampled($_new_image, $_image, 0, 0, 0, 0, $_new_width, $_new_height, $_width, $_height);
 
//输出图片
imagepng($_new_image);
 
//销毁新资源句柄
imagedestroy($_new_image);
//销毁原资源句柄
imagedestroy($_image);
 
 }

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/28.html

分享给朋友:

“PHP生成缩略图” 的相关文章

php抽奖概率算法

php抽奖概率算法

<?php /*  *算法学习自百度.只是学习和记录  */ header("Content-type:text/html;charset=utf-8"); //1.设置奖项,id是奖项id,name是中奖名称,v是中奖概率 $arr =&n...

php数组合并 array_merge和+号的区别

php数组合并 array_merge和+号的区别

array_merge是最常用的数组合并方法,+号同样也可以,但是却有很大不同。array_merge遇到相同字符串key,后面数组的key会覆盖前面数组的key,+号正好相反。$a = [ 'one' => 'A on...

php new class

php new class

<?php $member = new class {     public function getInfo()     {    ...

php pecl设置代理,php pear设置代理

php pecl设置代理,php pear设置代理

pear config-set http_proxy 47.94.200.124:3128 pecl config-set http_proxy 60.216.101.46:32868家里的长城宽带什么都上不去,安装php扩展真麻烦,使用网...

stream_socket_accept  peername和stream_socket_get_name

stream_socket_accept peername和stream_socket_get_name

stream_socket_accept  $peername参数将对应客户端的地址和端口输出:$conn = stream_socket_accept($socket,0,$peerName);127.0.0.1:57034输出连接的客户端的ip和端口而stream_...

php设置进程标题,php设置进程名称

php设置进程标题,php设置进程名称

    /**      * 设置进程标题      * @param string $title  &nbs...