头像

PHP原比例生成缩略图

2018-04-10 16:55:18 来源:PHP代码   浏览()   评论 ( 0 )   

<?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代码)并保留原文链接:http://www.phpdaima.com//master-53.html
广告不存在
评论0

后面还有条评论,点击查看>>

温馨提示:为规范评论内容,垃圾评论一律封号...