Page 1 of 2

How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T06:42:22-07:00
by Mofler
Hi!
I'd like to have an image consisting of nine (3x3) cells/tiles.
I then want to populate these cells with one large image taking up 4 cells, and three smaller images taking up one cell each. (like shown in http://postimg.org/image/3o1mk66ut/ )

I do this with

Code: Select all

convert c:\temp\image.jpg -crop 50x50% part.jpg
convert -rotate 180 part-1.jpg part-1.jpg 
convert -rotate 180 part-2.jpg part-2.jpg 
montage -adjoin image.jpg part-1.jpg  part-2.jpg part-0.jpg -geometry +40+40+40+40 result.jpg
remove-item part*.jpg
but I need to specify that image.jpg should occupy four cells, not one like it does now. How do I do this?

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T08:40:09-07:00
by GreenKoopa
We crossed, so my idea posted to the old topic. It follows a different technique so I left it there. It uses convert with -append and -gravity.
viewtopic.php?f=1&t=23573#p99528

Your diagram shows borders and (uneven) spacing. Are they desired, or are they for clarity like the letters?

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T10:00:59-07:00
by fmw42
I am confused by your diagram also

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T13:20:46-07:00
by Mofler
Thank you very much GreenKopa. Your code is exactly what I am after.
The spacing in my illustration is not intended, just me being sloppy.

I'd like some spacing between the images though, how would I add this?
My script (script.bat) is now the following:

Code: Select all

convert image.jpg -crop 50x50% part.jpg
convert -rotate 180 part-1.jpg part-1.jpg 
convert -rotate 180 part-2.jpg part-2.jpg 
convert -background white -gravity SouthEast image.jpg part-1.jpg +append ( part-2.jpg part-0.jpg +append ) -append result.jpg

del part*.jpg
Why can't i simply run this as a batch file?
I get the following error:

Code: Select all

c:\Temp>´╗┐convert image.jpg -crop 50x50 part.jpg
'´╗┐convert' is not recognized as an internal or external command,
operable program or batch file.
(I've edited the file in Notepad..)

(Sorry for the confusing illustration by the way..)

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T13:39:54-07:00
by GreenKoopa
That is odd. You must have some non-printable characters or encoding problem. Try retyping it into a new file. It's not an ImageMagick problem. Do remember that % has special meaning in batch files, so escape them to %%.

You could use -border to add borders or margins to images as needed before -append. Alternatively you could create spacer images (-size 1x1 xc:white) and -append them where needed. -append will join all images in one go. There are many options so if those don't work let me know what specifically you need.

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T14:07:20-07:00
by Mofler
Thank you very much once again!
Why are you putting the last two pieces in paranthesis?
I'd like to put all of this in a powershell script but it breaks on the paranthesis. I need a way to escape it to be run in PS.

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T14:20:26-07:00
by GreenKoopa
I believe your cryptic error is a UTF-BOM.

I wish I knew more about Powershell, but I don't. Parenthesis need to be escaped on several platforms.

I use parenthesis to limit the second +append to the images we want on the second row. Take them out to see what happens.

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T14:23:30-07:00
by snibgo
Mofler wrote:'´╗┐convert' is not recognized as an internal or external command,
You have saved your command file in Notepad as UTF-8 encoding. Those funny characters at the start say it is UTF-8. The Windows command interpreter doesn't like UTF-8 files.

Solution: save the file as ANSI encoding.

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T14:44:01-07:00
by GreenKoopa
Parenthesis could be avoided, but it would quickly become a mess. There must be some way to escape them. Backslash, backtick, quotes, something.

There is a Windows usage page, but nothing on Powershell. If you become a frequent ImageMagick user, sharing your Powershell tips, tricks, and traps would be appreciated by all.

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-12T15:02:47-07:00
by snibgo
Poweshell escaping:

Code: Select all

PS D:\web\im> convert rose: "(" "+clone" ")" -append r.png
PS D:\web\im> convert rose: `( "+clone" `) -append r.png
PS D:\web\im> convert rose: `( `+clone `) -append r.png

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-13T00:12:52-07:00
by Mofler
Thank you so much everybody!
I have to say that Imagemagick really stands out in terms of user involvement helping others.
I now have exactly what I need thanks to you.

The reason that I wanted to do this in Powershell and not bat is that I am an sysadmin and Powershell is the future for scripting on Windows so no need to do it any other way.

You have all helped me immensely.

This is my final script:

Code: Select all

convert image.jpg -crop 50x50% part.jpg
convert -rotate 180 part-1.jpg part-1.jpg 
convert -rotate 180 part-2.jpg part-2.jpg 
convert -background white -gravity SouthEast -bordercolor white -border 20 image.jpg part-1.jpg +append "("  -bordercolor white -border 20 part-2.jpg part-0.jpg +append ")" -append result.jpg

Remove-Item part*.jpg
Have a great week:)

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-13T01:55:33-07:00
by snibgo
Good stuff, but I strongly advise against storing intermediate results as JPG, as this loses quality.

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-13T03:02:55-07:00
by Mofler
Thanks snibgo!
What is the alternative?

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-13T07:27:05-07:00
by GreenKoopa
Intermediate jpegs work well enough for this command and this input, but can later lead to problems. A lower-quality (higher compression) input image can result in more loss per step. And some commands will amplify the loss. Better off safe unless you have a reason to do otherwise. I use png for intermediate files. Easy and compatible with everything. miff, ImageMagick's format, has advantages. It can store multiple images and so sometimes can be less intuitive for new users. Most efficient is to eliminate intermediate files, but sometimes this can leave code unreadable. ImageMagick is full of alternatives.

Placing operations before images is depreciated, so
convert -rotate 180 part-1.jpg part-1.jpg
should be
convert part-1.jpg -rotate 180 part-1.jpg
or this could be easily moved into the final command as
... "(" part-1.jpg -rotate 180 ")" ...

-bordercolor is a setting, which is persistent until changed. The second one is not needed, but not harmful. For example, -background white and -gravity SouthEast are used for every following append.

Re: How to specify what tile a image should occupy (montage)

Posted: 2013-06-13T11:24:00-07:00
by snibgo
Mofler wrote:Thanks snibgo!
What is the alternative?
I use png or tiff for development; miff for production. They all support 16 bits/channel and alpha channel, and don't lose any information. png is widely supported by image viewers. miff is faster.

jpg is 8-bit, no alpha, and generally loses information for every write/read.