howto fit label in box and rotate it (with background img)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

You can set background to "none" for a transparent background.

Alturnative for black and white labels you can select either a -compose multiply, or -compose screen to overlay such images. See IM Examples Alpha composition for more details.

Note also that -rotate rotates all images in memory. The first rotate only sees
one image "back.pjg" the second rotates the composted image.

You can clean up the order using...

Code: Select all

convert back.jpg -rotate -90 \
     -background black -fill white -size 300x label:"Lorem Ipsum" \
    -compose screen -composite -rotate +90 out.jpg
If you want to rotate the label only, then you need to put parenthesis around the label creation, and put the roatte after it.

Code: Select all

convert back.jpg \
     -background black -fill white -size 300x \
    \( label:"Lorem Ipsum" -rotate -90 \) \
    -compose screen -composite  out.jpg
Note that -gravity is not only used for poition gravity, but also justification of text, and overlay images. For examples of such use see, Practical Annotation Examples
http://www.cit.gu.edu.au/~anthony/graph ... #practical

Finally if you do not plan to generate a more complex componud font (see IM Examples on compund fonts) for overlaying, you can always -annotate the text directly onto the image canvas. Annotate can draw rotated or angled text, but of course needs an existing canvas to draw on, unlike label which creates its own canvas, as it is an image generator.

In summery I would suggest you look at IM Examples and study the sections
Text to Image Handling
Compund Font Effects
Annotating Images.

These three sections work as a block, and were actually first written for IM version 5!
(see the older abandoned IM v5 Examples linked from the top level IM examples page).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply