如何用ImageMagick将图片置于动态宽度固定高度文本左侧?
Solution for Placing Star Image to the Left of Dynamic-Width, Fixed-Height Text
To achieve placing your starImage.png to the left of the fixed-height (32px), dynamic-width text before overlaying the whole group onto your base image, you'll need to first combine the star and text into a single composite layer, then place that layer onto your original image. Here's the adjusted ImageMagick command:
convert inputImage.jpeg \ \( starImage.png -resize x32 \) \ \( -size x32 label:"Morning in paradise" \) \ -gravity Center +append \ -gravity South -geometry +0+40 -composite \ finalImage.png
Breakdown of the Command:
- Resize the star image: The first parenthetical command
( starImage.png -resize x32 )scales your star image to match the fixed 32px height of your text, preserving its aspect ratio for width. This ensures perfect vertical alignment with the text. - Generate the fixed-height text layer: The second parenthetical
( -size x32 label:"Morning in paradise" )creates your text layer with a strict 32px height; the width automatically adjusts to fit the length of your text (dynamic width, as you requested). - Combine star and text horizontally:
-gravity Center +appendaligns the star and text layers vertically at their centers, then appends them side-by-side (star on the left, text on the right) into one unified, movable layer. - Place the combined layer onto the base image: Finally,
-gravity South -geometry +0+40 -compositepositions the entire star+text group 40px above the bottom edge of yourinputImage.jpeg, matching the vertical offset from your original command.
This approach ensures the star stays anchored to the left of your dynamic-width text, while maintaining the fixed height and bottom-aligned placement you need.
内容的提问来源于stack exchange,提问作者chrisayn
相关产品推荐
相关产品推荐

