PHP实现原比例生成缩略图的方法
发布于 2016-02-17 05:18:30 | 107 次阅读 | 评论: 0 | 来源: 网友投递
PHP开源脚本语言PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。
这篇文章主要介绍了PHP实现原比例生成缩略图的方法,涉及PHP的图形操作及数学运算相关技巧,非常简单实用,需要的朋友可以参考下
本文实例讲述了PHP实现原比例生成缩略图的方法。分享给大家供大家参考,具体如下:
$image = "jiequ.jpg"; // 原图
$imgstream = file_get_contents($image);
$im = imagecreatefromstring($imgstream);
$x = imagesx($im);//获取图片的宽
$y = imagesy($im);//获取图片的高
// 缩略后的大小
$xx = 140;
$yy = 200;
if($x>$y){
//图片宽大于高
$sx = abs(($y-$x)/2);
$sy = 0;
$thumbw = $y;
$thumbh = $y;
} else {
//图片高大于等于宽
$sy = abs(($x-$y)/2.5);
$sx = 0;
$thumbw = $x;
$thumbh = $x;
}
if(function_exists("imagecreatetruecolor")) {
$dim = imagecreatetruecolor($yy, $xx); // 创建目标图gd2
} else {
$dim = imagecreate($yy, $xx); // 创建目标图gd1
}
imageCopyreSampled ($dim,$im,0,0,$sx,$sy,$yy,$xx,$thumbw,$thumbh);
header ("Content-type: image/jpeg");
imagejpeg ($dim, false, 100);
?>
相关阅读:
PHP实现原比例生成缩略图的方法
php实现水印文字和缩略图的方法示例
php实现根据url自动生成缩略图的方法
php使用timthumb生成缩略图的方法
Thinkphp调用Image类生成缩略图的方法
php实现根据词频生成tag云的方法
PHP实现获取并生成数据库字典的方法
PHP生成透明背景PNG缩略图的方法
php按百分比生成缩略图的代码示例
php 根据url自动生成缩略图并处理高并发的问题解决方法
PHP生成图片缩略图的方法详解
兼容性比较好的PHP生成缩略图的代码