Imposition howto's during SI5

From XPUB & Lens-Based wiki

Clone imposition script from the scan-utils. git clone

How to program an imposition of different images (of different ratios and orientations) into a single sheet of paper? Creating a Print Signature?




same size source images

Imagemagick is a powerful tool to perform all sorts of manipulations on images, and one that affords many options concerning resizing.

How to resizes images which we want in the imposition onto files of the same dimensions? Taking into consideration the images':

  • have different ratios and orientations,
  • should not be cropped or distorted .

One option that seems to work is to place the images onto frames of the same size.

For creatime same size frames Imagemagick provides the -extent operator, which adjusts the final size of an image , without resizing it.

But According to IM documentation, "[i]f the image size increases, space will be added to right or bottom edges of the image. If it decreases the image data is just junked or cropped to fit the new image size."

convert -background black -extent 297x421 -gravity Center input.jpg output.jpg

If the input image

  • is larger than 297x421 you'll get a cropped image,
  • is smaller than 297x421 space will be added to right or bottom edges of the image.

-gravity defines where the center of the image should be. Possible values: Center North, South, East, West

As cropping or junking the image is something we want to avoid, a solution might be to also resize the image to the same dimensions given to -extent using the -resize parameter

convert -background black original.jpeg -gravity Center -resize 297x421 -extent 297x421 extend_297x421.jpeg

01 extent.png

To perform that operation in all images of a directory, we can use a for loop:

for i in dir/*; do convert -background black $i -gravity Center -resize 297x421 -extent 297x421 extent_$i;done

Imagemagick: Montage

After resizing all images, the next step, towards the imposition, is to use those images to create a mosaic using the IM montage command.

It is useful to look at the bash script featured in this Scribus page on imposition to get a few hints on how this is done. Although programming such a task in bash is a daring and messy job :).

In its simplest form a 4x2 montage can be invoked with:

montage -geometry +1+1 -tile 4x2 01.png 02.png 03.png 04.png 05.png 06.png 07.png 08.png 4x2.jpg

  • -geometry '+1+1' defines the spacing between tiles:+from_left_to_right+from_top_to_bottom
  • -tile 4x2: how the tiled images are to be laid out


Imagemagick Montage: Order & Rotation

Notice that the distribution of tiles goes from top left to bottom right. Such order, wont result in a correct page ordering when folded into a booklet.

To achieve the correct page ordering for the book let we'll have to provide the order:

  • single-side: [3, 6, 5, 4, 2, 7, 8, 1]
  • double-sided: [5, 12, 9, 8, 4, 13, 16], [1, 7, 10, 11, 6, 2, 15, 14, 3]

montage -geometry +1+1 -tile 4x2 03.png 06.png 05.png 04.png 02.png 07.png 08.png 01.png 4x2_order.jpg

4x2 order.jpg

As the top part of the imposition sheet will be folded down, its content will be inverted in the booklet. To correct that we can rotate the uppper 4 tiles 180 degrees with -rotate 180.

montage -geometry +1+1 -tile 4x2 \( -rotate 180 03.png 06.png 05.png 04.png \) 02.png 07.png 08.png 01.png 4x2_top180.jpg

4x2 top180.jpg

page size

If IM's identify is asked provide to give information on A4 and A3 pdfs: identify A4.pdf. I will get the following reply:

  • A4 210x297mm 8.3x11.7inch 2480x3508px (at 300 dpi) 595x842 (at 72dpi)
  • A3 297x420mm 11.7x16.5inch 3508x4960px (at 300 dpi) 842x1191px (at 72dpi)

Note the size in pixels changes when in relation to the resolution: 300 or 72 pdi.

The resulting value is nothing more than: page_height_inches*resolution X page_height_inches*resoltuion

(8.3inch * 300dpi) X (11.7inch * 300dpi) = 2480x3508px

More of paper sizes in inch,mm,px:

convert to page size

After creating the montage with the same ratio as A4 & A3 the next step will be convert it to a PDF with the right dimensions PDF, so it can be sent to the printer.

convert 4x2.jpg -gravity Center -resize 3508x2480 -units PixelsPerInch -density 300x300 4x2_a4_300dpi.pdf

Produces a PDF with 3508x2480px and 11.6x8.26inch

  • -units specifies the units of image resolution: Undefined, PixelsPerInch, or PixelsPerCentimete
  • -density specifies the resoltion
  • -gravity Center resize gravity point


Johansson, Kay; Lundberg, Peter. Robert Ryberg, ed. A Guide to Graphic Print Production. Wiley.