Batch Convert & Montage Jpeg Files

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
photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Batch Convert & Montage Jpeg Files

Post by photoboothnwb » 2019-01-06T23:05:27-07:00

I was previously able to convert a watermark onto an image, but I was wondering if someone could guide me to create a script that would:

1. From a folder, containing total of 3 images in .jpg, montage any 2 images together in -tile 0x2, reducing the dimensions so that the height would be 4"
2. Montage the resulting 2 images together with the remaining image for a total of 6x4" post card
3. Add a watermark/border to the final image (one on bottom left and one on bottom right)
4. Print to printer using CUPS

I want it to create something like this:
https://www.dropbox.com/s/mty3rf6qjax0j ... e.jpg?dl=0

I've been really struggling to attempt to create such a script, and have spent countless hours on researching to no avail. I would really appreciate it if someone could help me! it's for an upcoming wedding photobooth. This is all running on raspberry pi.
Thank you!

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

Re: Batch Convert & Montage Jpeg Files

Post by fmw42 » 2019-01-07T11:38:21-07:00

What OS? What version of Imagemagick? Note that -tile 0x2 is wrong. It should be 1x2. Imagemagick does not work in inches. You will need to work in pixels and set the density for your output jpg so that you get 6x4 in based upon the pixel dimensions.

___________________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli

photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Batch Convert & Montage Jpeg Files

Post by photoboothnwb » 2019-01-07T11:50:26-07:00

Sorry, Version: ImageMagick 6.9.7-4 Q16 arm 20170114 running on Raspberry Pi 3b

Can you maybe provide a template for me to start, and how I would go about in montaging one 1x2 with another picture (of bigger size), and then converting a water mark on top? I've been at it for hours to no avail :(

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

Re: Batch Convert & Montage Jpeg Files

Post by fmw42 » 2019-01-07T12:15:21-07:00

Post your 3 images and the text you want. Note that you can use montage for this. But you can also use +- smush, which is like append, but allows offsets. You may have to resize the images you want. Smush or montage the two smaller ones top and bottom, then smash or montage that result with the larger one. Then you can use montage to add text below or you can create a text image and smush it below the result. Alternately, you can just create a background image and composite each component image. If you provide your images, I can show you some unix syntax code with Imageamagick. You are going to have to do some computations first to convert your dimensions in inches into pixels for Imagemagick to work.

photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Batch Convert & Montage Jpeg Files

Post by photoboothnwb » 2019-01-07T21:23:35-07:00

fmw42 wrote:
2019-01-07T12:15:21-07:00
Post your 3 images and the text you want. Note that you can use montage for this. But you can also use +- smush, which is like append, but allows offsets. You may have to resize the images you want. Smush or montage the two smaller ones top and bottom, then smash or montage that result with the larger one. Then you can use montage to add text below or you can create a text image and smush it below the result. Alternately, you can just create a background image and composite each component image. If you provide your images, I can show you some unix syntax code with Imageamagick. You are going to have to do some computations first to convert your dimensions in inches into pixels for Imagemagick to work.
Sorry, I've been at work all day, just got back home now. Here are the three example images of exact size that is produced by the photobooth app.

https://www.dropbox.com/s/tnfj8nygyoghq ... 1.jpg?dl=0
https://www.dropbox.com/s/2sva1zhudejhg ... 2.jpg?dl=0
https://www.dropbox.com/s/adf9t5exdpu30 ... 3.jpg?dl=0

Here's the watermark/logo that should be on bottom right side on top of the images:
https://www.dropbox.com/s/kodco0meacta3 ... k.png?dl=0

Thanks again for the quick replies and great help!

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

Re: Batch Convert & Montage Jpeg Files

Post by fmw42 » 2019-01-07T22:20:59-07:00

Here's the watermark/logo that should be on bottom right side on top of the images:
Sorry I do not understand. How can the watermark be at the bottom and on the top? Do you mean "top" as overlay.

Is the watermark image, the size that you want for the output, thus scaling the other 3 to fit inside that? Or do you care how big the output is in pixels? At 72 dpi, 6x4 inches = 72*6 x 72*4 = 432x288. The pixel dimensions actually do not matter as long as they are in the ratio of 6:4, but the larger the image pixels likely means the higher the quality. However, the pixel dimensions of the output will determine how large or small the watermark text will be as it has to be scaled to those dimension. Your watermark image is 600x400 pixels so 6:4 aspect ratio. So I will just use that and make the rest fit to it.

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

Re: Batch Convert & Montage Jpeg Files

Post by fmw42 » 2019-01-07T22:47:24-07:00

Here is code for a unix-like system. Since your watermark image is 600x400, I will use that for the size. 6inx4in would require a density of 100 dpi (6*100=600 px and 4*100=400 px). This is one of many ways that this can be created. I simply resize and composite your images over a white background of size 600x400 at specific offsets. Aspect ratio must be preserved by the resize so that you do not distort your images. So I only specify the width and let the height be determined automatically to preserve the aspect. See https://imagemagick.org/script/command- ... p#geometry and https://imagemagick.org/Usage/layers/#convert

Code: Select all

convert \
\( -size 600x400 xc:white \) \
\( yellow.jpeg -resize 370x \) -geometry +19+29 -compose over -composite \
\( green.jpeg -resize 187x \) -geometry +398+29 -compose over -composite \
\( blue.jpeg -resize 187x \) -geometry +398+175 -compose over -composite \
\( watermark.png \) -geometry +0-10  -compose over -composite \
-density 100 result.jpg
Image

P.S. IM 6.9.7.4 is rather old. You might consider upgrading. Current version is 6.9.10.23.

photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Batch Convert & Montage Jpeg Files

Post by photoboothnwb » 2019-01-09T10:08:43-07:00

I'm getting the following error when I run the script:

Code: Select all

convert-im6.q16: unable to open image `)(': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
Here's the code that I put in the .sh script:

Code: Select all

#!/bin/bash
cd
cd Desktop/IN
convert \
\( -size 600x400 xc:white \)\
\( GROUP-1-1.jpg -resize 370x \) -geometry +19+29 -compose over -composite \
\( GROUP-1-2.jpg -resize 187x \) -geometry +398+29 -compose over -composite \
\( GROUP-1-3.jpg -resize 187x \) -geometry +398+175 -compose over -composite \
\( watermark.png \) -geometry +0-10  -compose over -composite \
-density 100 GROUP-1-RESULT.jpg

snibgo
Posts: 11444
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch Convert & Montage Jpeg Files

Post by snibgo » 2019-01-09T10:20:39-07:00

You need a space before and after every ( and every ) .
snibgo's IM pages: im.snibgo.com

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

Re: Batch Convert & Montage Jpeg Files

Post by fmw42 » 2019-01-09T10:44:23-07:00

As per snigbo's comment look here and put a space.

#!/bin/bash
cd
cd Desktop/IN
convert \
\( -size 600x400 xc:white \)\
\( GROUP-1-1.jpg -resize 370x \) -geometry +19+29 -compose over -composite \
\( GROUP-1-2.jpg -resize 187x \) -geometry +398+29 -compose over -composite \
\( GROUP-1-3.jpg -resize 187x \) -geometry +398+175 -compose over -composite \
\( watermark.png \) -geometry +0-10 -compose over -composite \
-density 100 GROUP-1-RESULT.jpg

photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Batch Convert & Montage Jpeg Files

Post by photoboothnwb » 2019-01-09T11:01:22-07:00

that works! thank you very much guys!

photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Batch Convert & Montage Jpeg Files

Post by photoboothnwb » 2019-01-20T20:37:08-07:00

I have a follow up request to this script...is it possible to add another layer to this convert script so that each .jpg file gives an increasing sequential number (in the form of a text/font, not a manually generated .jpg/png file overlay) starting from #1-999 and overlay it to the top left corner? for example GROUP-1-RESULT.jpg will auto generate "#1" on top left corner, as will GROUP-2-RESULT.jpg have "#2", and so forth. Thanks for any help!

Edit: The file already generates sequential numbers via "${seq}", was hoping to use the annotate command to place whatever ${seq} is equal to (a number) to the top left with a small font size.

Edit2: nm, i think i solved it: -pointsize 50 -gravity south-east -annotate +20+5 "#${seq}" \

Post Reply