PHP实现原比例生成缩略图的方法

yipeiwu_com6年前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基本语法入门教程》及《php常用函数与技巧总结

希望本文所述对大家PHP程序设计有所帮助。

相关文章

一个简单的php加密解密函数(动态加密)

复制代码 代码如下:function encode_pass($tex,$key,$type="encode"){    $chrArr=array('a'...

PHP计算当前坐标3公里内4个角落的最大最小经纬度实例

本文实例讲述了PHP计算当前坐标3公里内4个角落的最大最小经纬度的方法。分享给大家供大家参考,具体如下: //$lng 、$lat 经纬度 $half = 6371;...

DEDE采集大师官方留后门的删除办法

去除官方后门方法:安装好采集大师后,请立即删除 include目录下的dedesql.query.php文件,如已经安装过,有可能文件已被改名为arc.sqlquery.class.ph...

PHP遍历目录并返回统计目录大小

复制代码 代码如下: <?php $dirname = "test1"; //mkdir($dirname); //遍历一层目录 function listdir($dirname...

php数组保存文本与文本反编成数组实例

本文实例讲述了php数组保存文本与文本反编成数组的方法。分享给大家供大家参考。具体实现方法如下: 下面的实例定义了两个函数,其中string2array用于将字符串转换成数组,array...