【发布时间】:2018-07-05 15:37:58
【问题描述】:
我想在多张图片上对角放置水印。由于这些图像的尺寸各不相同,但水印应始终以恒定比例具有最大可能大小,因此我必须计算调整大小的完美角度。 (它应该看起来像that。不像that。)
我使用以下算法:
ratio1 = pic1_width / pic1_height
ratio2 = pic2_width / pic2_height
angle = atan ((ratio1 - ratio2) / (1 - ratio1 * ratio2))
详细解释见here。
有没有办法在图像处理过程中动态地进行这种计算?
我在 Ubuntu Linux 上使用 ImageMagick 6.8.9-9 Q16 x86_64。
在 Bash 中,它可能看起来像这样(没有调整大小):
convert -background none -gravity center -density 300 "$pic" \
\( "$wmark" -rotate "%[fx:atan(((u.w/u.h)-(v.w/v.h))/(1-(u.w/u.h)*(v.w/v.h)))]" \) \
-compose over -composite "$result"
代码不会旋转图像。我认为这是因为“-rotate”不接受“%[fx:]”参数?不幸的是,到目前为止,我还没有找到有关此的明确信息... 此外,变量“w”和“h”的值似乎是“0”……我也不明白。
最好的问候
AFeee
【问题讨论】:
-
您需要升级到 ImageMagick v7 才能在
-rotate参数中进行替换。您还需要使用magick -background ...而不是convert -background ... -
感谢您的建议。同时,我切换到IM7。我的问题的解决方案可以在 ImageMagick 论坛的this thread 下找到。
标签: image image-processing imagemagick image-manipulation imagemagick-convert