I'd like to place a watermark diagonally 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:
ratio1 = pic1_width / pic1_height
ratio2 = pic2_width / pic2_height
angle = atan ((ratio1 - ratio2) / (1 - ratio1 * ratio2))
For a detailed explanation see here.
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 (without the resizing):
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"
The code does not rotate the image. I think that's because "-rotate" does not accept "%[fx:]" arguments? Unfortunately, I have not been able to find clear information about this so far ... In addition, the variables "w" and "h" seem to have the value "0" ... which I also do not understand.
Best regards
AFoeee
-rotate
parameter. You'd also need to usemagick -background ...
rather thanconvert -background ...
– Mark Setchell