Fred's ImageMagick Scripts


    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at:

    Please read the Pointers For Use on my home page to properly install and customize my scripts.


Converts an image into a tilable texture.

Download Script

last modified: December 16, 2018

USAGE: tiler [-m method] [-o overlap] [-v vpmethod] infile outfile
USAGE: tiler [-h or -help]

-m .... method ...... method of overlap blending; choices are 1 or 2;
..................... 1 is simple average blending; 2 is ramped blending;
..................... default=1
-o .... overlap ..... seam overlap amount in pixels; integer>=0; default=2
-v .... vpmethod .... virtual-pixel method used to extend the quadrants;
..................... any valid IM non-background virtual-pixel method
..................... is allowed. Best choices seem to be mirror or edge;
..................... default=mirror

NOTE: the input image (infile) must be square and have even dimensions.

PURPOSE: To convert an image into a tilable texture.

DESCRIPTION: TILER converts an image into a tilable texture. It does this by swapping diagonal quadrants, exending the borders to get overlap and then composite blending the extended quadrants. The extension and blending attempt to minimize or avoid manual painting/blurring/cloning along the seams.


-m method ... METHOD of overlap blending. The choices are 1 or 2. Method 1 is a simple average blending. Method 2 is a ramped blending. The default=1.

-o overlap ... OVERLAP is amount of extension of the quadrants in order to cover the center horizontal and vertical seems. Values are integers>=0. The default=2

-v vpmethod ... VPMETHOD is the virtual-pixel method used to extend the quadrants. Any valid IM non-background virtual-pixel method is allowed. Recommended values are either mirror or edge. The default is mirror.

Requirement: IM 6.5.3-4 or higher due to the use in method 1 of convert ... -compose blend -define compose:args=50,50 -composite ...

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


Example: Rocks

Original Image

Quadrant Swap Only:
convert rocks256.jpg -roll +128+128 rocks256roll.jpg

-m 1 -o 2 -v mirror

2x2 Tiling
convert -size 512x512 tile:rocks256_tile_mirror.jpg rocks256_tiled512.jpg

Example: Dirt

Original Image

Quadrant Swap Only:
convert dirt256.jpg -roll +128+128 dirt256_roll.jpg

-m 1 -o 2 -v mirror

2x2 Tiling
convert -size 512x512 tile:dirt256_tile_mirror.jpg dirt256_tiled512.jpg

Example: Random

Original Image

Quadrant Swap Only:
convert random256.jpg -roll +128+128 random256roll.jpg

-m 1 -o 2 -v mirror

2x2 Tiling
convert -size 512x512 tile:random256_tile_mirror.jpg random256_tiled512.jpg

What the script does is as follows:

  • Crops each quadrant of the original image and unfolds the relevant edges
  • Rolls the original image half way
  • Does a blend composite of each successive quadrant over the rolled image

This is equivalent to the following IM commands for method 1

  • wd=`convert $infile -ping -format "%w" info:`
  • ht=`convert $infile -ping -format "%h" info:`
  • ww=`convert xc: -format "%[fx:$wd/2]" info:`
  • hh=`convert xc: -format "%[fx:$ht/2]" info:`
  • wwo=`convert xc: -format "%[fx:$ww+$overlap]" info:`
  • hho=`convert xc: -format "%[fx:$hh+$overlap]" info:`
  • rollamount="+${ww}+${hh}"
  • cropsize="${ww}x${hh}+0+0"
  • www=$(($ww+$overlap))
  • hhh=$(($hh+$overlap))
  • sesize="${www}x${hhh}+0+0"
  • swsize="${www}x${hhh}-$overlap+0"
  • nesize="${www}x${hhh}+0-$overlap"
  • nwsize="${www}x${hhh}-$overlap-$overlap"
  • gsize=$(($overlap + 2))
  • convert $infile \
    \( -clone 0 -gravity southeast -crop $cropsize +repage -virtual-pixel $vp \
    -define distort:viewport=$sesize -distort SRT 0 +repage \) \
    \( -clone 0 -gravity southwest -crop $cropsize +repage -virtual-pixel $vp \
    -define distort:viewport=$swsize -distort SRT 0 +repage \) \
    \( -clone 0 -gravity northeast -crop $cropsize +repage -virtual-pixel $vp \
    -define distort:viewport=$nesize -distort SRT 0 +repage \) \
    \( -clone 0 -gravity northwest -crop $cropsize +repage -virtual-pixel $vp \
    -define distort:viewport=$nwsize -distort SRT 0 +repage \) \
    \( -clone 0 -roll $rollamount \
    -clone 1 -gravity northwest -compose blend -define compose:args=50,50 -composite \
    -clone 2 -gravity northeast -compose blend -define compose:args=50,50 -composite \
    -clone 3 -gravity southwest -compose blend -define compose:args=50,50 -composite \
    -clone 4 -gravity southeast -compose blend -define compose:args=50,50 -composite \) \
    -delete 0-4 \