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

PHP生成缩略图

高老师8年前 (2017-07-02)PHP1629
//参数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 开启错误提示,php 关闭错误提示

开启错误提示代码:ini_set("display_errors", "On"); error_reporting(E_ALL | E_STRICT);关闭错误提示代码:error_reporting(E_ALL ^&n...

php scoket,php webscoket,php webscoket 服务器

php scoket,php webscoket,php webscoket 服务器

项目需要使用websocket推送最新订单,客户服务器非linux不支持swoole,因此使用原生,直接上代码(1).PHP服务端<?php ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set...

php创建webservice,php搭建webservice,php编写webservice

php创建webservice,php搭建webservice,php编写webservice

第一步:服务端文件<?php $wsdlfile='webservice.wsdl'; ini_set('soap.wsdl_cache_enabled','0');    //关闭WSDL缓存 //001...

php trait的使用

php trait的使用

PHP不像net支持多继承,自身只支持单继承,为了解决这个问题,php出了Trait这个特性,减少单继承语言的限制。并且能让代码复用率更高。说白了就是一个对象的属性和方法扩展工具一样。例如:trait exts {     public f...

php new class

php new class

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

php代理下载,php代下载文件,php下载远程文件,php远程文件下载

php代理下载,php代下载文件,php下载远程文件,php远程文件下载

经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。<?php //设置下载文件的url $url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19....