Page 2 of 3

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-17T20:41:03-07:00
by snibgo
"-label" is on each; "-title" is on the overall montage.

Code: Select all

montage logo2t_check.jpg logo2t_check.jpg logo2t_check.jpg logo2t_check.jpg logo2t_check.jpg logo2t_check.jpg -background none -geometry +10+10 -tile 4x -title "A contact sheet" logo2t_montage.png
Image

(The image has 4 sub-images in the first row, with "A contact sheet" centred above them.)

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-17T20:52:18-07:00
by snibgo
I cross-posted the above about "-title" with ohai, and "-title" may be useful but probably isn't what is wanted here.

Yes, montage can take *.tga or *.png.

The initial composite can't, so just use a Windows "For" loop, eg:

Code: Select all

FOR %%F in (*.tga) do composite -compose Dst_over -tile pattern:checkerboard %%f %~nF.png
del contact_montage.png
del output.png
montage *.png -background none -geometry +10+10 -tile 4x -title "A contact sheet" contact_montage.png
convert backdrop.jpg contact_montage.png output.png

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-17T21:33:53-07:00
by ohai
What substitution are you going for with %~nF.png ?

When I run that block from a batch file I get:

Code: Select all

E:\img_output>montage.bat
The following usage of the path operator in batch-parameter
substitution is invalid: %~nF.png

For valid formats type CALL /? or FOR /?
montage.bat was unexpected at this time.
On running the 'FOR help' I don't see a %~nF as a variable option. %~n is there but no capital 'F'... I'm on WinXP SVC PK3, though I wouldn't think it would make a difference in this instance...

-ohai

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-17T21:35:03-07:00
by fmw42
Can the label be an appended image, or does it have to be a text label? I'll read up on the 'label' function but just thought I'd ask.
Yes, you can append any number of images together.

But if you have a background image that has the title at the top and you just want to overlay the montage, then resize the montage so that the height is smaller than the background by enough to show the title and let the width adjust in proportion and then overlay the resized montage.

convert backgroundimagewithtitle \( montage -resize 480x480 \) -gravity south -compose over -composite resultimage

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T00:46:01-07:00
by snibgo
My first line should have had "%%F" instead of "%%f", and "%%~nF" instead of "%~nF". I was hacking this very late at night, sorry.

Code: Select all

FOR %%F in (*.tga) do composite -compose Dst_over -tile pattern:checkerboard %%F %%~nF.png
In %~nF, F is the name of the variable. %~nF is the name, without path or extension, of the file %F.

This is on Windows 7.

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T09:29:21-07:00
by ohai
Hehehe, no worries. I thought I tried everything I could think of before my head hit the keyboard and I passed out. :)

Is there a way to make this work on filenames that have spaces in them? It chokes on spaces in the filenames. However, I started brainstorming a few ideas and I think I'm kinda sorta onto something, though being an IM noob is hindering progress... Here's what I'm trying:

Code: Select all

FOR %%F IN (*.tga) DO composite -compose Dst_over -tile pattern:checkerboard -size 10x10 %%F %%~nF.png
montage *.png -background "transparent" -depth 8 -type TrueColorMatte -geometry 110x110+9+9 -tile 4x3 Grid.png
convert e:\img_output\IM_RSRC\Header.png Grid.png -append Merged.png
Here's what I did prior to that:

I renamed all the files to 01.tga 02.tga 03.tga etc etc, just for the testing phase, though getting this to work on filenames with spaces is going to be a necessity.

I replaced -tile 4x with -tile 4x3 in montage and noticed that if there are >12 images and the output of that line is Grid.tga, it stops after creating Grid.tga (leaving out the 13th+ files)

If there are >12 images with -tile 4x3 and the output of montage is Grid.png, it creates Grid-0.png and Grid-1.png and so on.. so that'll be good for larger folders (though I'm not sure how to handle the wildcards/substitutions for '-0' and '-1' and '-etc' when it comes to using those in later steps, but anyway, for testing purposes I've restricted this to a folder of less than 12 images just so I could see if it'll work in concept)

I cropped the header area from the original backdrop image and saved it as a separate 512x128 image called Header.png

The convert line of my batch code generates an error and I'm not sure why

Code: Select all

E:\img_output>convert e:\img_output\IM_RSRC\Header.png Grid.png -append Merged.png
Invalid Parameter - Grid.png
still working on it, but basically what I'm attempting is:
1. montage the 4x3 Grids (Grid-0.png, Grid-1.png, Grid-2.png and so on... automatically at 512x384 and transparent backgrounds)
2. append the new 512x128 header.png vertically above the 512x384 Grid PNGs (which should give me 512x512 images), and then save as Merged-0.png, Merged-1.png etc etc
3. Superimpose 512x512 Merged.png over the original 512x512 "Backdrop.png" (the one with the lightly textured background) and save as AlmostDone.png, though this step isn't in my batch code yet because the append step isn't working...

SIDE NOTE: appended files don't have to all be the same dimensions do they? Is it the colon in the e:\path\ ?

4. Superimpose 512x512 Copyright.png over AlmostDone.png and save as FinallyDone.png :)

-ohai

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T09:58:16-07:00
by snibgo
Is there a way to make this work on filenames that have spaces in them?
Put the filename between double-quotes, eg "c:\my directory\my file.png" or "%%~nF.png"
E:\img_output>convert e:\img_output\IM_RSRC\Header.png Grid.png -append Merged.png
Invalid Parameter - Grid.png
That's the messge you'll get if you run the DOS convert.exe program (which converts filesystems, which you should probably avoid) instead of the IM convert. You can get round the problem by:

a) putting the IM directory at the start of your path, instead of the end OR
b) renaming the IM convert to, for example, imconvert.exe, then running that instead OR
c) set an environment variable eg IMG to the IM directory, then running %IMG%convert.

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T13:28:37-07:00
by ohai
Awesome, thanks.. I renamed it to imconvert.exe and it works now... I've got everything working up to and including step 5 from the list I made in my earlier post.. Basically my batch code now creates the grid, appends the header image above the grid and saves it, superimposes that over the backdrop, and superimposes the copyright watermark over the whole thing. So.. woohoo!

Here's my batch code as of now:

Code: Select all

FOR %%F IN (*.tga) DO composite -compose Dst_over -tile pattern:checkerboard -size 10x10 "%%F" "%%~nF.png"
montage *.png -background "transparent" -depth 8 -type TrueColorMatte -geometry 118x118+5+5 -tile 4x3 -shadow Grid.png
imconvert e:\img_output\IM_RSRC\Header.png Grid.png -append Merged.tga
composite Merged.tga e:\img_output\IM_RSRC\Contact_Sheet_Backdrop.tga AlmostDone.tga
composite e:\img_output\IM_RSRC\Copyright_Grid.tga AlmostDone.tga FinallyDone.tga
del *.png
del Merged.tga
del AlmostDone.tga
Can the last 2 composite lines be done in a single step by holding the intermediate image in memory, rather than doing multiple saves which potentially degrade image quality? They're TGA so the damage is probably next to nothing but still it would be nice and maybe cleaner.

Also, there need to be several substitutions, in the "convert" line as well as the final two composite lines, for folders of >12 images, but I'm not sure how to approach those. I understand the logical structure/hierarchy of what needs to be done but it's the specific syntax that's eluding me.

Lastly, to get this to work recursively from within the top-level "Images" directory I'll need to use some kind of FOR /R (*.*).. I think... but still reading up on how to approach that.

-ohai

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T14:57:46-07:00
by snibgo

Code: Select all

imconvert e:\img_output\IM_RSRC\Header.png Grid.png -append Merged.tga
composite Merged.tga e:\img_output\IM_RSRC\Contact_Sheet_Backdrop.tga AlmostDone.tga
composite e:\img_output\IM_RSRC\Copyright_Grid.tga AlmostDone.tga FinallyDone.tga
These three can be merged into one command, without saving the intermediate results. The input files for convert (with "-composite") is the opposite order to the composite command, so it's something like this (untested):

Code: Select all

imconvert e:\img_output\IM_RSRC\Header.png Grid.png -append ^
  e:\img_output\IM_RSRC\Contact_Sheet_Backdrop.tga +swap -composite ^
  e:\img_output\IM_RSRC\Copyright_Grid.tga -composite ^
  FinallyDone.tga
If you want to maintain image quality, you might move that "-depth 8" to the large imconvert, just before the output filname. In this particular case, it probably won't make any difference, but it's good to get into the habit of leaving image degredation to the end.

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T16:31:12-07:00
by ohai
I just removed "-depth 8" entirely since there's no need for it.

I've modded the first line to

Code: Select all

FOR /R %%F IN (*.tga) DO composite -compose Dst_over -tile pattern:checkerboard -size 10x10 "%%F" "%%~nF.png"
and it seems to be the right beginning but not sure how to handle the processing of the folders. Currently by simply adding the /R it processes images in subfolders but it outputs the contact sheet to the root level folder (the folder from which the command was run) and not within each respective folder. Additionally, it takes thumbnails from both of my test folders/subdirectories and combines them in a single contact sheet.

I don't know if I should be looking at the character substitutions for folders >12 images first, or dealing with the recursion first. I keep bouncing back and forth between the two as I hit a wall and ending up not making any progress.

-ohai

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T16:47:17-07:00
by fmw42
Here is another way to do it without montage (using append)

1)convert xc: montage.png

2)convert \( logo3t.png -compose copy -bordercolor red -border 10 \) \
\( logo3t.png -channel rgba -alpha on -bordercolor red -border 10 \) \
+append montage.png +swap -append montage.png

3)convert \( logo3t.png -compose copy -bordercolor red -border 10 \) \
\( logo3t.png -bordercolor red -border 10 \) \
+append montage.png +swap -append -gravity north -chop 0x1 montage.png

4)composite -compose Dst_over -tile pattern:checkerboard montage.png montage.png

5)convert \( \( -size 512x512 xc:blue \) \
\( -size 512x32 -background none -fill white -gravity northeast label:"TESTING" \) \
-compose over -composite \) \
\( montage.png -resize 480x480 \) -gravity south -compose over -composite montage.png

Image

1) just creates a dummy image to use for appending
2) appends your first two images in a row with a red border keeping transparency (-compose copy)
3) appends your next two images in a row with a red border keeping transparency (-compose copy), then appends the two rows, then chops off the first row that came from the dummy image
4) puts a checkerboard behind the whole appended 4 images
5) creates a blue background of size 512x512, creates a label and overlays it at the top left of the blue image, then resizes the appended image to allow room for the label, then overlays the reduced appended image at the bottom of the blue image with the label showing at the top.

If you have more images to append, then you can write a loop to append them row by row and finally append all the rows.

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T17:07:45-07:00
by snibgo
For the recursion, I would do this:

for /R %%D in (.) do call DoOneDir.bat %%D

Where DoOneDir.bat contains the commands above, with two changes: the initial FOR comand will be
FOR %%F IN (%1\*.tga) ...
and the final output will be to %1\FinallyDone.tga


For the Grid-0.png, Grid-1.png, etc I would write another FOR loop that, well, loops through them, doing the imconvert on each one, to produce (n) output files. Obviously, they couldn't all be called FinallyDone.tga, so they might be named contact-Grid-0.tga, contact-Grid-1.tga etc.

The temporary intermediate files would go in the directory you run the command from. You could instead put them in the subdirectory or %TEMP%, if you want.

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T17:44:44-07:00
by ohai
fmw42 wrote:Here is another way to do it without montage (using append)
Thanks for these examples fmw42.. I'm going through them trying to gain more familiarity with the way commands are commonly structured in IM.. All of this is very new to me.. I'm mostly a visual artist. Scripting and programming and LOOPing and FORing and all of it is making me dizzy. :)
snibgo wrote: For the Grid-0.png, Grid-1.png, etc I would write another FOR loop that, well, loops through them, doing the imconvert on each one, to produce (n) output files. Obviously, they couldn't all be called FinallyDone.tga, so they might be named contact-Grid-0.tga, contact-Grid-1.tga etc.
That's something I've been forgetting to ask because managing the final output of approx 1200 folders and 16000 images is going to be a headache in itself... Is there a way to insert the folder name as the title of the sheet for that folder? For example, if the images are contained in a folder called \toplevel\Sub Folder Name\ and I'm running the recursive batch file from within \toplevel\ the sheets are output as so:

\toplevel\Sub Folder Name\Sub Folder Name sheet-0.tga
\toplevel\Sub Folder Name\Sub Folder Name sheet-1.tga
\toplevel\Another Folder Name\Another Folder Name sheet-0.tga
\toplevel\Another Folder Name\Another Folder Name sheet-1.tga
and so on...

Is that even possible?

-ohai

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-18T18:45:22-07:00
by snibgo
Is that even possible?
Yes. This is an IM forum, not a DOS command-syntax forum, but DoOneDir.bat can contain %~p0, which will expand to the directory that contains the batch file. If the first argument is, as I suggest, a directory, then you might use %%~p0\%%1\%%F as a label. (Within a batch file, you need to double the percents.)

Re: Help needed creating layered contact sheet w/ alpha tran

Posted: 2010-05-20T00:04:42-07:00
by ohai
I think I made a little bit of progress with this by adding a second FOR loop and using a +adjoin before the final output filename:

Code: Select all

FOR %%F IN (%1\*.tga) DO composite -compose Dst_over -tile pattern:checkerboard -size 10x10 "%%F" "%%~nF.png"
montage *.png -background "transparent" -type TrueColorMatte -geometry 120x120+4+4 -tile 4x3 Grid.png
FOR %%G IN (Grid*.png) DO (
imconvert e:\img_output\IM_RSRC\Header.tga "Grid*.png" ^
	-append e:\img_output\IM_RSRC\Backdrop.tga +swap ^
	-composite e:\img_output\IM_RSRC\Copyright_Grid.tga ^
	-composite "%%G" +adjoin %1\ContactSheet.png )
This now adds a -1, -2 on the final contact sheets. However, it only processes the -append and -composite stages (where it layers the copyright, grid, and backdrop) for the first 12 images. The 13th and higher images are not processed and are seemingly output as just the bare grid from the montage line, though they *do* get named properly as ContactSheet-2.png, etc. I'm not sure why it only does the convert process for the first Grid-# output from the montage line.

-ohai