Return to Snippet

Revision: 48822
at July 11, 2011 05:47 by miohtama

Initial Code
def process_floor_image(infile, outfile, copy_pics):
    Copy the orignal image and make also 1024 x 1024 sliced tiles out of it. 
    Because our green robot friend sucks.    
    @return Image size in [width, height]
    im =
    w = im.size[0]
    h = im.size[1]
    dimensions = [ w, h ]
    if copy_pics:
        # Copy master
        path = os.path.dirname(outfile)
        base = os.path.basename(outfile)
        except OSError:
        print "Copying image:" + outfile
        shutil.copyfile(infile, outfile)
        # slice the image to 1000 x 1000 tiles
        slice_size = 1000
        for y in range(0, h, slice_size):
            for x in range(0, w, slice_size):
                fname = os.path.join(path, "tile-%d-%d-%s" % (x, y, base)) 
                print "Creating tile:" + fname
                mx = min(x+slice_size, w)
                my = min(y+slice_size, h)
                buffer ="RGB", [slice_size, slice_size], (255, 255, 255))                                
                tile = im.crop((x, y, mx, my))
                buffer.paste(tile, (0, 0))                                
      , "PNG")
    return dimensions

Initial URL

Initial Description
Create smaller tiles out of a larger bitmap image

Initial Title
Slicing images with Python and PIL

Initial Tags

Initial Language