源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-10-19 02:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/455.htm]PHP图形与图片操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/348.htm]PHP基本语法入门教程[/url]》及《[url=http://www.1sucai.cn/Special/168.htm]php常用函数与技巧总结[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部