I'd like to place a watermark over a number of images. Since the dimensions of these images vary, but the watermark should always have the maximal possible size at constant proportions, I have to calculate the perfect angle for the resizing. (It should look like that. Not like that.)
I use the following algorithm:
Code: Select all
ratio1 = pic1_width / pic1_height
ratio2 = pic2_width / pic2_height
angle = atan ((ratio1 - ratio2) / (1 - ratio1 * ratio2))
Is there any way to do this calculation dynamically during image processing?
I'm using ImageMagick 6.8.9-9 Q16 x86_64 on Ubuntu Linux.
In Bash it might look something like this:
Code: Select all
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"
In addition, the variables "w" and "h" seem to have the value "0" ... which I also do not understand.
I would like to extend GeeMacks solution from this thread.
Best regards
AVoeee