@@ -0,0 +1,1542 @@
+#!/usr/bin/python%0A#%0A# This is a helper script to ensure an image has the correct tile size.%0A# It uses pgmagick%5B1%5D to read and (if needed) correct the image. To use%0A# it on a number of files one could use e.g. the find command:%0A#%0A#   find %3Cdata-folder%3E -name *.jpg -exec scripts/ensure_tilesize.py %7B%7D 256 %5C;%0A#%0A# %5B1%5D http://pypi.python.org/pypi/pgmagick/%0A%0Aimport sys%0Aimport os%0Afrom pgmagick import Image, Geometry, Color, CompositeOperator as co%0A%0A# Make sure we got the arguments we expect%0Aif len(sys.argv) != 3:%0A    print %3E%3E sys.stderr, %22Usage: ensure_tilesize.py %3CFILENAME%3E %3CTILESIZE%3E%22%0A    sys.exit(1)%0A%0Aimage_path = sys.argv%5B1%5D%0Atile_size = int(sys.argv%5B2%5D)%0A%0A# Make sure the file actually exists%0Aif not os.path.exists(image_path):%0A    print %3E%3E sys.stderr, %22Could not find file!%22%0A    sys.exit(1)%0A%0A# Get properties of image%0Aimage = Image(image_path)%0Aimage_width = image.size().width()%0Aimage_height = image.size().height()%0Aimage_name = image.fileName()%0A%0A# If the image has the correct size, just exit%0Aif image_width == tile_size and image_height == tile_size:%0A    sys.exit(0)%0A%0A# A new image with the correct size is needed, create it%0Ageometry = Geometry(tile_size, tile_size)%0Acolor = Color(%22black%22)%0Anew_image = Image(geometry, color)%0A# Copy original image to position 0,0 of new image%0Anew_image.composite(image, 0, 0, co.OverCompositeOp)%0A# Override original image%0Anew_image.write(image_name)%0A%0Aprint %3E%3E sys.stdout, %22Corrected %22 + image_name + %22 from %22 + str(image_width) + %22x%22 + str(image_height) + %22 to %22 + str(tile_size) + %22x%22 + str(tile_size)%0A%0A

Add script to ensure the correct tile size of a file