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

PHP生成缩略图

高老师9年前 (2017-07-02)PHP1733
//参数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     $a=0.5*100;     if(is_int($a)){   echo'int'; } else{ echo'not int';   }    ...

PHP对象转数组

PHP对象转数组

function objtoarr($obj){ $ret = array(); foreach($obj as $key =>$value){ if(gettype($value) == 'arr...

 php 判断是否post,php判断是否post提交,php 判断是否为post,php 判断get 还是post

php 判断是否post,php判断是否post提交,php 判断是否为post,php 判断get 还是post

if($_SERVER['REQUEST_METHOD'] == 'POST') { echo('This is  post '); } elseif ($_SERVER['...

 php xml字符串转数组,phpxml转数组,php 将xml转换成数组

php xml字符串转数组,phpxml转数组,php 将xml转换成数组

001源码:/*  * $xml_str是xml字符串  */ function  xmltoarray($xml_str) { //禁止XML实体扩展攻击 libxml_disable_entity_loader(true); //拒绝包含...

php迭代器学习

php迭代器学习

php官方已经提供了Iterator(迭代器)接口,通过网上资料的学习,目前看适合超大集合或者数组提取使用。学习一个函数的实现对比内存占用差距.使用迭代器和普通循环实现range()函数。(1).普通循环实现range()函数。function newrange($low, $h...