为什么我的机器上的范围(imagemagick)的行为不均匀? [英] why is the behavior of extent (imagemagick) not uniform across my machines?

查看:122
本文介绍了为什么我的机器上的范围(imagemagick)的行为不均匀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rmagick / imagemagick中的extent将图像置于特定大小的画布上。

I'm using extent in rmagick/imagemagick to center images on a canvas of certain size.

在我的某些机器上,它将它们集中在其他机器上反其道而行之。如果我修复代码在一台机器上工作,那么它就完全相反了。

On some of my machines, it centers them - on others it does the opposite. If I fix code to work on one machine, it does the exact opposite on the other.

有谁知道为什么会这样?

Does anyone know why this is happening?

推荐答案

我其实已经知道了答案 - 经过5个小时的代码挣扎。只是张贴这个作为参考。

I actually already knew the answer -- after 5 hours of struggling with code. Just posting this for reference.

对于一些未知(我认为很愚蠢)的原因,这出现在ImageMagick更改日志中:

For some unknown (and I think stupid) reason , this appeared in the ImageMagick changelog:

2010-09-13 6.6.4-2 Cristy <quetzlzacatenango@image...>
# Don't negate the geometry offset for the -extent option.

无论出于何种原因,ImageMagick团队认为可以更改功能 LITERALLY在一个版本中已经有历史性地完成

For whatever reason, the ImageMagick team decided it was okay to change a function to do LITERALLY THE EXACT OPPOSITE OF WHAT IT HAS HISTORICALLY DONE in a release .

该函数应保持原样,新行为的推论函数可能有已经介绍了,原来的功能已被弃用 - 有警告 - 在几个版本中。

The function should have remained as-is, a corollary function with the new behavior could have been introduced, and the original function been deprecated - with warnings - over several releases.

像这样的策略 - 这几乎是处理这类变更的标准方法 - 可以让那些拥有针对ImageMagick构建的活动代码的人正常继续。相反,人们现在必须编写支持此功能的两个版本的代码,或者强制升级。

A strategy such as this - which is pretty much the standard way of handling changes like this - would have allowed those with active code built against ImageMagick to continue as normal. Instead, people now have to write code supporting both versions of this function, or forcing upgrades.

以下ruby代码是如何处理这个问题的一个例子,因为你有没有想法,有人会在他们的机器上运行什么版本。

the following ruby code is an example of how to handle this, as you have NO IDEA WHATSOEVER what version someone will be running on their machine.

offset_coords= { 'x' => 100 , 'y' => 100 }
expects_negated = true
# ImageMagick 6.6.4-2 changed the behavior of extent
# me: !(*@&#(#! .
#mversion = "ImageMagick 6.6.4-1 2010-12-07 Q16 http://www.imagemagick.org"
mversion = Magick::Magick_version
( v_version , v_commit ) = mversion.split(' ')[1].split('-')
( v_version_1 , v_version_2 , v_version_3 ) = v_version.split('.')
if Integer(v_version_1) >= 6 and Integer(v_version_2) >= 6 and Integer(v_version_3) >= 4 and Integer(v_commit) >= 2
    expects_negated= false
end
if expects_negated 
    offset_coords['x'] = - offset_coords['x']
    offset_coords['y'] = - offset_coords['y']
end

@new_image.background_color= "#000000"
@new_image = @new_image.extent( target_dimensions['w'] , target_dimensions['h'] , offset_coords['x'] , offset_coords['y'] )

这篇关于为什么我的机器上的范围(imagemagick)的行为不均匀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆