You forgot to add 16 (or 15 if inclusive rect) to the boundaries. The code should read: pngminx = minx*16 pngmaxx = maxx*16+16 pngminz = minz*16 pngmaxz = maxz*16+16 pngregion=[pngminx, pngmaxx, pngminz, pngmaxz] Using the current code (without +16), [pngregion[1]-pngregion[0], pngregion[4]-pngregio...