def partition(width, height, n=3):
    """
    Given the pixel width and pixel height of a rectangular image and an integer ``n``, partition the rectangle into ``n**2`` subrectangles, each of roughly the same sizes.
    Return a list of the subrectangle offsets and sizes for easy use with  GDAL's ``gdal_translate -srcwin`` option.
    Each list item has the form (x-offset, y-offset, x-size, y-size) and the items/subrectangles are ordered from left to right and then from top to bottom, e.g. for ``n=3`` the layout of the subrectangles looks like this::

        -------------
        | 0 | 1 | 2 |
        -------------
        | 3 | 4 | 5 |
        -------------
        | 6 | 7 | 8 |
        -------------

    The subrectangles in the right-most column and those in the bottom-most row will be slightly wider and taller, respectively, than the other subrectangles in case ``width`` or ``height`` are not divisible by ``n``, respectively.
    """
    q, r = divmod(width, n)
    xs = [(i*q, q) for i in range(n - 1)] + [((n - 1)*q, q + r)]
    q, r = divmod(height, n)
    ys = [(i*q, q) for i in range(n - 1)] + [((n - 1)*q, q + r)]
    return [(xoff, yoff, xsize, ysize) for yoff, ysize in ys
      for xoff, xsize in xs]