记一次图片压缩过程的BUG处理
来源:互联网 发布:python lambda *_ 编辑:程序博客网 时间:2024/05/22 02:20
2017-12-15 19:58:59[10][-][-][error][Imagine\Exception\OutOfBoundsException] exception 'Imagine\Exception\OutOfBoundsException' with message 'Cannot paste image of the given size at the specified position, as it moves outside of the current image's box' in /data/vendor/imagine/imagine/lib/Imagine/Gd/Image.php:128Stack trace:#0 /data/vendor/yiisoft/yii2-imagine/BaseImage.php(175): Imagine\Gd\Image->paste(Object(Imagine\Gd\Image), Object(Imagine\Image\Point))#1 /data/modules/ImageAction.php(73): yii\imagine\BaseImage::thumbnail('/data/ru...', 453.33333333333, 800)#2 [internal function]: app\modules\ImageAction->run()#3 /data/vendor/yiisoft/yii2/base/Action.php(92): call_user_func_array(Array, Array)#4 /data/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\Action->runWithParams(Array)#5 /data/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('image', Array)#6 /data/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('risk/audit/imag...', Array)#7 /data/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))#8 /data/web/index.php(19): yii\base\Application->run()#9 {main}2017-12-15 19:58:59[][-][-][error][application] Exception Cannot paste image of the given size at the specified position, as it moves outside of the current image's box
------------------
题主在图片尺寸处理时没有经过intval,导致在】/vendor/yiisoft/yii2-imagine/BaseImage.php中
/** * Creates a thumbnail image. The function differs from `\Imagine\Image\ImageInterface::thumbnail()` function that * it keeps the aspect ratio of the image. * @param string $filename the image file path or path alias. * @param integer $width the width in pixels to create the thumbnail * @param integer $height the height in pixels to create the thumbnail * @param string $mode * @return ImageInterface */public static function thumbnail($filename, $width, $height, $mode = ManipulatorInterface::THUMBNAIL_OUTBOUND){ $box = new Box($width, $height); $img = static::getImagine()->open(Yii::getAlias($filename)); ....... if ($size->getWidth() < $width) { $startX = ceil($width - $size->getWidth()) / 2; } if ($size->getHeight() < $height) { $startY = ceil($height - $size->getHeight()) / 2; } $thumb->paste($img, new Point($startX, $startY)); return $thumb;}
/vendor/imagine/imagine/lib/Imagine/Gd/Image.php
/** * {@inheritdoc} */ final public function paste(ImageInterface $image, PointInterface $start) {..... $size = $image->getSize(); if (!$this->getSize()->contains($size, $start)) { throw new OutOfBoundsException( 'Cannot paste image of the given size at the specified '. 'position, as it moves outside of the current image\'s box' ); }..... }
/vendor/imagine/imagine/lib/Imagine/Image/Box.php
/** * {@inheritdoc} */public function contains(BoxInterface $box, PointInterface $start = null){
return $start->in($this) && $this->width >= $box->getWidth() + $start->getX() && $this->height >= $box->getHeight() + $start->getY();
}
if ($size->getWidth() < $width) { $startX = ceil($width - $size->getWidth()) / 2; } if ($size->getHeight() < $height) { $startY = ceil($height - $size->getHeight()) / 2; }此处会出现$startX=0.5;
进而,导致在
contains
方法里返回false,从而抛异常。
解决方式:直接intval一下入参的尺寸
- 记一次图片压缩过程的BUG处理
- 记一次 BUG 的排查过程
- 一次心脏滴血漏洞的bug处理过程
- 记一次bug解决过程
- 记一次HIS系统的expdp/impdp过程中的BUG
- 记一次erlang分布式系统的bug修复过程
- 记一次使用 git bisect 快速定位 bug 的过程
- 图片的压缩处理
- 记录一次软件Bug发生的过程
- 一次BUG定位的过程与总结
- 记一次CEdit的bug
- 记一次神秘的BUG
- 记一次愚蠢的BUG
- 对图片的压缩处理
- ios图片的压缩处理
- 记一次游戏识别图片验证码的过关过程
- 记一次Hive元数据管理问题的处理过程
- 一次TempDB损毁的处理过程
- android studio app运行时 红叉
- JavaEE资源分享:Redisd总结
- 从零开始开发一个大型网站
- [RK3399][Android7.1] 调试笔记 --- 系统使用的分区文件
- 微信小程序实例系列
- 记一次图片压缩过程的BUG处理
- flex:1代表什么意思
- php最后输出时有空行
- layer组件的使用
- 【运维】Dell R710如何开启VT服务
- LeetCode 16 3Sum Closest
- 12月19日云栖精选夜读:开源PaaS工具CloudFoundry落地阿里云
- XML 语法规则
- 学习10