Compose multiple images together (for rating)

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
i.ivan
Posts: 3
Joined: 2018-07-13T08:09:44-07:00
Authentication code: 1152

Compose multiple images together (for rating)

Post by i.ivan » 2018-07-13T08:17:27-07:00

Hi,
I'm trying to learn how to use imagemagick but, like a newbie, I have a lot of difficulties.

  1. I want to create an image size 1040x508, white background
  2. on the left side I want to include the image of the product with a maximum height of 400px
  3. on the right I want to insert a box that contains the rating of the product, as shown:
Image

I started from the right box but I stopped because I do not know how to complete it. Can anyone kindly help me?

Code: Select all

convert \
-background transparent \
-font "./fonts/opensans/OpenSans-Bold.ttf" \
-fill "#fff" -pointsize 100 \
label:"3.5" rate.png

convert \
-background transparent \
-font "./fonts/opensans/OpenSans-Light.ttf" \
-fill "#fff" -pointsize 33 \
label:"out of 10" outof10.png

convert \
-background transparent \
-font "./fonts/opensans/OpenSans-BoldItalic.ttf" \
-fill "#fff" -pointsize 33 \
label:"to avoid" textReview.png
resources:

User avatar
fmw42
Posts: 23648
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compose multiple images together (for rating)

Post by fmw42 » 2018-07-13T09:38:17-07:00

Please always provide your Imagemagick version and platform.

This works for me. Composite two images at a time. Use -annotate to place your text. Use parenthesis processing to separate the processing for each image separately.

Code: Select all

convert -respect-parentheses background.png \
\( product.jpg -resize x400 \) \
-gravity west -geometry +100+0 -compose over -composite \
\( red_box.png -fill white \
-font "/Library/fonts/OpenSans-Bold.ttf" -pointsize 100 -gravity center -annotate +0-100 "3.5" \
-font "/Library/fonts/OpenSans-Light.ttf" -pointsize 33 -gravity center -annotate +0-15 "out of 10" \
-font "/Library/fonts/OpenSans-BoldItalic.ttf" -pointsize 33 -gravity center -annotate +0+110 "to avoid" \) \
-gravity west -geometry +500+0 -compose over -composite \
corona.jpg
Adjust the -geometry and annotate offsets as desired for fine tuning

i.ivan
Posts: 3
Joined: 2018-07-13T08:09:44-07:00
Authentication code: 1152

Re: Compose multiple images together (for rating)

Post by i.ivan » 2018-07-14T11:01:30-07:00

Thank you very much for the help you give this community every day!

Your script is just what I needed!
I have only one small change to make. Where it is written "to avoid" there may be a text that stands on two lines. How can this be done?

p.s. I use ImageMagick 7.0.8-6

User avatar
fmw42
Posts: 23648
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compose multiple images together (for rating)

Post by fmw42 » 2018-07-14T11:43:22-07:00

If you know where you want to break it into two lines, then try adding a new line character such as "to\navoid"

Code: Select all

convert -respect-parentheses background.png \
\( product.jpg -resize x400 \) \
-gravity west -geometry +100+0 -compose over -composite \
\( red_box.png -fill white \
-font "/Library/fonts/OpenSans-Bold.ttf" -pointsize 100 -gravity center -annotate +0-100 "3.5" \
-font "/Library/fonts/OpenSans-Light.ttf" -pointsize 33 -gravity center -annotate +0-15 "out of 10" \
-font "/Library/fonts/OpenSans-BoldItalic.ttf" -pointsize 33 -gravity center -annotate +0+110 "to\navoid" \) \
-gravity west -geometry +500+0 -compose over -composite \
corona.jpg
If you need automatic line breaking, you cannot use -annotate. You would have to create separate text images on transparent backgrounds using caption: and then composite them onto your red_box image at the correct locations.

i.ivan
Posts: 3
Joined: 2018-07-13T08:09:44-07:00
Authentication code: 1152

Re: Compose multiple images together (for rating)

Post by i.ivan » 2018-07-16T12:55:25-07:00

hello and thank you very much for all your help which was very helpful to me!!

Post Reply