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

PHP生成缩略图

高老师9年前 (2017-07-02)PHP1867
//参数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对象转数组

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

php 将数组键值转为变量

php 将数组键值转为变量

<?php $data=array('a'=>1,'b'=>2,'c'=>3,'d'=>4); extract($data); var_dump($a,$b,$c,$d); ?>在人人商城中捡到的...

php定义常量数组

php定义常量数组

<?php //php7+ define('CONFIG', [     'MYSQL' => '127.0.0.1',     ...

php elasticsearch基础使用

php elasticsearch基础使用

elasticsearch的操作都是基于http协议的,已经有现成的php类库,composer安装即可。{     "require": {        &...

php中0和字符串比较时注意的问题

php中0和字符串比较时注意的问题

在正式介绍前先抛出一段代码:<?php //输入的密码 $password = empty($_POST['password']) ? 0 : $_POST['password']; //设置的密码...

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扩展真麻烦,使用网...