PHP 图片等比例缩放不失真
来源:互联网 发布:祖马龙 知乎 编辑:程序博客网 时间:2024/05/18 02:36
<?php/** * 图片等比例缩放类 * @author zhx */class ImgThumbnail {private $source;private $imageinfo;private $image;private $percent = 0.1;private $newImageName;/** * @param string $source 图片url * @param string $percent 默认就可以 * @param unknown $newImageName保存图片的名称 */public function __construct( $source, $percent, $newImageName ) {$this->source = $source;$this->percent = $percent;$this->newImageName = $newImageName;$this->openImage();$this->thumpImage();$this->showImage();$this->saveImage();}/** * 打开图片 * @author zhx */public function openImage() {list ( $width, $height, $type, $attr ) = getimagesize ( $this->source );$this->imageinfo = array ('width' => $width,'height' => $height,'type' => image_type_to_extension ( $type, false ),'attr' => $attr);$fun = "imagecreatefrom" . $this->imageinfo ['type'];$this->image = $fun ( $this->source );}/** * 操作图片 * @author zhx */public function thumpImage() {$new_width = $this->imageinfo ['width'] * $this->percent;$new_height = $this->imageinfo ['height'] * $this->percent;$image_thump = imagecreatetruecolor ( $new_width, $new_height );// 将原图复制带图片载体上面,并且按照一定比例压缩,极大的保持了清晰度imagecopyresampled ( $image_thump, $this->image, 0, 0, 0, 0, $new_width, $new_height, $this->imageinfo ['width'], $this->imageinfo ['height'] );imagedestroy ( $this->image );$this->image = $image_thump;}/** * 输出图片 * @author zhx */public function showImage() {header ( 'Content-Type: image/' . $this->imageinfo ['type'] );$funcs = "image" . $this->imageinfo ['type'];$funcs ( $this->image );}/** * 保存图片到硬盘 * @author zhx */public function saveImage() {$funcs = "image" . $this->imageinfo ['type'];$funcs ( $this->image, $this->newImageName . '.' . $this->imageinfo ['type'] );}/** * 销毁图片 * @author zhx */public function __destruct() {imagedestroy ( $this->image );}}# 调用示例// $image = new ImgThumbnail( $url , 0.2, 'test' );
阅读全文
0 0
- PHP 图片等比例缩放不失真
- PHP图片缩放函数:实现等比例不失真缩放
- PHP中图片实现等比例不失真缩放
- 图片不失真比例缩放
- jquery获取select中的option的text值|| PHP图片缩放函数:实现等比例不失真缩放
- php实现等比例生成图片缩略图不失真
- 不失真缩放图片
- 等比例缩略图不失真
- 图片等比例大小拉伸,保持最大限度不失真
- 使用PHP制作等比例缩放图片
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 等比例缩放图片
- 等比例缩放图片
- linux vim查找替换撤销
- 如果遇到Xshell键盘无法使用,你需要这样做!
- 文件系统的挂载过程
- java_多线程_解决生产者消费者问题_用最简单的代码
- GKDecisionNode
- PHP 图片等比例缩放不失真
- bzoj1912 [Apio2010]patrol 巡逻(树的直径[变式])
- C++调用C#dll
- Django权限机制的实现
- MFC中使用串口控件后程序无法打开的问题解决
- RAW(裸) 与 QCOW2(写时复制) 的区别
- 计算文字所占大小
- 安装jdk的过程
- 升级Xcode中SDK与真机调试版本