Create a contact sheet

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, xnview

Post Reply
azev
Posts: 2
Joined: Wed Feb 13, 2019 11:51 am

Create a contact sheet

Post by azev » Wed Feb 13, 2019 11:53 am

Is it possible to create a contact sheet with nconvert?
I want to combine various .jpg in one sheet.

User avatar
xnview
Author of XnView
Posts: 31340
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Create a contact sheet

Post by xnview » Thu Feb 14, 2019 12:12 pm

no sorry
Pierre.

azev
Posts: 2
Joined: Wed Feb 13, 2019 11:51 am

Re: Create a contact sheet

Post by azev » Fri Feb 15, 2019 4:00 pm

Image

cday
XnThusiast
Posts: 2088
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Create a contact sheet

Post by cday » Fri Feb 15, 2019 8:06 pm

azev wrote:
Fri Feb 15, 2019 4:00 pm
Image

If you are desperate for a command line solution, there could be a quite limited workaround:

The watermark function can in fact be considered as a general paste function, as it pastes one image onto another, and the pasted image need not have transparency.

The watermark function has limited positioning options, but could for example be used to paste four images onto the four corners of an existing image canvas of suitable size which needn't be blank, or nine images onto an existing canvas; some other options are no doubt possible.

Quite limited, and implementation would need a batch file with multiple NConvert lines to paste each image successively, so only really potentially useful for very repetitive rather than general application.

The options available are as follows:

Code: Select all

 -wmfile file      : Watermark file (Must be after other -wm commands)
          -wmpos x y        : Watermark position
          -wmflag flag      : Watermark position
              top-left, top-center, top-right
              center-left, center, center-right
              bottom-left, bottom-center, bottom-right
          -wmopacity value  : Watermark opacity (0-100)
          -wmstretch        : Stretch image

cday
XnThusiast
Posts: 2088
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Create a contact sheet

Post by cday » Mon Feb 18, 2019 8:59 pm

An illustration of how the watermark option mentioned above may be used to create a simple contact sheet:

The following code can be used to place an image 1.png at the top left of an existing canvas:

Code: Select all

nconvert -wmflag top-left -wmfile Image1.png -out png -o Result.png Canvas.png
Result_1.png
Result_1.png (2.99 KiB) Viewed 330 times

And the following code run in a batch file can be used to place two images on to the same blank canvas:

Code: Select all

nconvert    -wmflag top-left  -wmfile Image1.png -out png -o a.png  Canvas.png
nconvert -D -wmflag top-right -wmfile Image2.png -out png -o Result.png  a.png
Result_2.png
Result_2.png (4.61 KiB) Viewed 330 times

The following code can be used to place four images on the same canvas:

Code: Select all

nconvert    -wmflag top-left     -wmfile Image1.png -out png -o a.png  Canvas.png
nconvert -D -wmflag top-right    -wmfile Image2.png -out png -o b.png       a.png
nconvert -D -wmflag bottom-left  -wmfile Image3.png -out png -o c.png       b.png
nconvert -D -wmflag bottom-right -wmfile Image4.png -out png -o Result.png  c.png
Result_4.png
Result_4.png (7.55 KiB) Viewed 330 times


This method of creating a contact sheet clearly has limitations, and would normally only be applicable to repetitive situations, but it is not in fact quite as limited as stated in the above post, as the following option can be used to place an image at any arbitrary position on a canvas:

Code: Select all

-wmpos x y        : Watermark position
But yes, it could become tedious... :wink:

cday
XnThusiast
Posts: 2088
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Create a contact sheet

Post by cday » Sun Mar 03, 2019 7:40 pm

Further development with several enhancements to the above code:

First, the following line of code inserted at the start of the script allows the use of source images of any supported format, and renumbers the source files so that standard filenames can be used during further processing:

Code: Select all

nconvert -D -out png -o Input\Image##.png Input\*.* 

Second, the following additional line of code automatically creates a canvas of the required size on which to paste the source images:

Code: Select all

nconvert -resize 200%% 200%% -out png -o Canvas.png Input\Image01.png

Adding the additional code to the code to generate a 2x2 contact sheet in the previous post, and making some detailed changes required, gives the following code:

Code: Select all

nconvert -D -out png -o Input\Image##.png Input\*.* 
nconvert -resize 200%% 200%% -out png -o Canvas.png Input\Image01.png

nconvert -D -wmflag top-left     -wmfile Input\Image01.png -out png -o a.png  Canvas.png
nconvert -D -wmflag top-right    -wmfile Input\Image02.png -out png -o b.png       a.png
nconvert -D -wmflag bottom-left  -wmfile Input\Image03.png -out png -o c.png       b.png
nconvert -D -wmflag bottom-right -wmfile Input\Image04.png -out png -o Result.png  c.png
The above code should be regarded as outline code in which the file formats can be changed and to which compression can be added as required; the code above uses the lossless PNG format without compression, and as a result the contact sheet generated has a large filesize.

Similar code with minor adjustments if required can be incorporated into scripts for other possible contact sheet layouts.

Here is a 2x2 contact sheet created from four Microsoft images using the above code:

Result.jpg

Note: The posted image has been converted to JPEG format so that the size is below the forum attachment limit.

So NConvert can be used without too much difficulty to create contact sheets... :D

Post Reply