/**
* 生成缩略图
* $imgSrc 图片源路径
* $resize_width 图片宽度
* $resize_height 图片高度
* $dstimg 缩略图路径
* $isCut 是否剪切图片
*/
public function reSizeImg($imgSrc, $resize_width, $resize_height, $dstimg, $isCut = false) {
//图片的类型
$type = substr(strrchr($imgSrc, "."), 1);
//初始化图象
if ($type == "jpg" || $type == "jpeg") {
$im = imagecreatefromjpeg($imgSrc);
}
if ($type == "gif") {
$im = imagecreatefromgif($imgSrc);
}
if ($type == "png") {
$im = imagecreatefrompng($imgSrc);
} $width = imagesx($im);
$height = imagesy($im); //生成图象
//改变后的图象的比例
$resize_ratio = ($resize_width) / ($resize_height);
//实际图象的比例
$ratio = ($width) / ($height);
if (($isCut) == 1) {
if ($ratio >= $resize_ratio) {
//高度优先
$newimg = imagecreatetruecolor($resize_width, $resize_height);
imagecopyresampled($newimg, $im, 0, 0, 0, 0, $resize_width, $resize_height, (($height) * $resize_ratio), $height);
ImageJpeg($newimg, $dstimg);
}
if ($ratio < $resize_ratio) {
//宽度优先
$newimg = imagecreatetruecolor($resize_width, $resize_height);
imagecopyresampled($newimg, $im, 0, 0, 0, 0, $resize_width, $resize_height, $width, (($width) / $resize_ratio));
ImageJpeg($newimg, $dstimg);
}
} else {
if ($ratio >= $resize_ratio) {
$newimg = imagecreatetruecolor($resize_width, ($resize_width) / $ratio);
imagecopyresampled($newimg, $im, 0, 0, 0, 0, $resize_width, ($resize_width) / $ratio, $width, $height);
ImageJpeg($newimg, $dstimg);
}
if ($ratio < $resize_ratio) {
$newimg = imagecreatetruecolor(($resize_height) * $ratio, $resize_height);
imagecopyresampled($newimg, $im, 0, 0, 0, 0, ($resize_height) * $ratio, $resize_height, $width, $height);
ImageJpeg($newimg, $dstimg);
}
}
ImageDestroy($im);
}

  

最新文章

  1. Visual Studio 2015 和 Apache Cordova 跨平台开发入门(一)
  2. Jetty 的工作原理以及与 Tomcat 的比较
  3. 加入Tomcat插件到ECLIPSE中的方法
  4. Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法【转载】
  5. TJI读书笔记12-接口
  6. Unity3D引用dll打包发布的问题及解决
  7. 解决android的ListView嵌套在ScrollView中不能被滚动的问题
  8. HDU 4858 项目管理(邻接表 暴力模拟)
  9. POJ 3286 How many 0&#39;s?(数位DP)
  10. django访问静态文件
  11. Delphi各个版本和发展历史(转)
  12. 分享我们项目中基于EF事务机制的架构 【转载】
  13. vue2.0+elementUI构建单页面后台管理平台
  14. LogBack学习
  15. 项目管理之 SVN 管理软件 CornerStone for Mac
  16. 从一个word文件中读取所有的表格和标题(2)
  17. Java课程设计报告——购物车
  18. Linux framebuffer deferred io机制
  19. Docke--Dockerfile指令介绍
  20. leetcode感想

热门文章

  1. Gradle 设置本地meaven
  2. C++学习013多态
  3. 第三十四篇 Python面向对象之 反射(自省)
  4. CCF-NOIP-2018 提高组(复赛) 模拟试题(七)
  5. Laxcus大数据管理系统2.0 (1) - 摘要和目录
  6. Visual Studio 2010安装包
  7. LeetCode 74——搜索二维矩阵
  8. windows下git hub的GUI软件配置与使用
  9. liniux备忘录-磁盘配额与进阶文件系统管理
  10. 基于phonegap,html5,ratchet,handlebars等技术的微表情APP