代码点火器resize()



我使用resize()来调整缩略图的大小。我的源图像是1024 * 768。这是我的配置

 $demo= array(
                  'source_image' => $x['full_path'],
                  'new_image' => $this->image,
                  'maintain_ratio' => true,
                  'create_thumb' => true,
                  'width' => 192,
                  'height' => 92
                );

但是我的图像被调整为123 * 98。为什么不使用width值

您已经启用了maintain_ratio选项,因此CI将尝试创建缩略图,"尽可能接近目标宽度和高度,同时保留原始长宽比"

在你的例子中,你有一个尺寸为1024x768的图像,宽高比为1.33854(1024/768)。

这对应于一个192x143的缩略图或一个123x92的缩略图,使用你指定的宽度和高度值。

CI认为123x92更合适(可能基于缩略图的面积)。

123 x98

为什么?可能是调整大小算法的一些工件(数学四舍五入的错误?)。

需要查看CI代码的详细信息才能得到更精确的答案。

脚注
有一些关于CI图像调整大小的讨论,在模块中有一些怪癖:

[quote author="Saete" date="1346125636"]You will not beleive me, 
y had the same problem and y changed the order of configuration parameters 
with the maintain_ratio = true, and it worked :S
I needed to adjust to height:
Didn't work:
$config['width'] = 126;
$config['height'] = 84;
$config['maintain_ratio'] = TRUE;
Worked!
$config['height'] = 84;
$config['width'] = 126;
$config['maintain_ratio'] = TRUE;
Some years later, but it may help someone...[/quote]

显然,参数的顺序会产生影响(这肯定是一个bug)。
参考:http://ellislab.com/forums/viewthread/119169/# 594586

相关内容

最新更新