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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

不是JS   2021-03-20 我要评论
想了解PHP实现原比例生成缩略图的方法的相关内容吗,不是JS在本文为您仔细讲解PHP原比例生成缩略图的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们