UESPWiki:Oblivion Map Design/CreateZoomLevels.py

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search

The following a rough Python script for creating all zoom levels from the renamed set of base images output from the Oblivion CS. Change the file paths used in the script to reflect where the images are stored and saved on your computer.

import os
import sys
import Image
import shutil

def makeFilename(outx, outy, zoom):
        return FilePath + 'zoom%(zoom)d\\tamriel-%(outx)d-%(outy)d-%(zoom)d.jpg' % \
                    {'outx': outx, 'outy': outy, 'zoom': zoom }

FilePath = 'f:\\obmaps\\renamejpgs\\'
NullFile = 'f:\\obmaps\\renamejpgs\\nullimage.jpg'
StartZoom = 15
EndZoom = 8
StartX = 0 * 1
StartY = 0 * 1
NumX = 134 * 1
NumY = 129 * 1
CurrentZoom = StartZoom

for CurrentZoom in range(StartZoom, EndZoom, -1):
    StartY = int(StartY / 2)
    StartX = int(StartX / 2)
    NumX = int(NumX / 2)
    NumY = int(NumY / 2)
    for XIndex in range(StartX, StartX+NumX, 2):
        for YIndex in range(StartY, StartY+NumY, 2):
            FileNW = makeFilename(XIndex, YIndex, CurrentZoom)
            FileNE = makeFilename(XIndex+1, YIndex, CurrentZoom)
            FileSW = makeFilename(XIndex, YIndex+1, CurrentZoom)
            FileSE = makeFilename(XIndex+1, YIndex+1, CurrentZoom)
    
            try:
                ImageNW = Image.open(FileNW)
            except IOError:
                ImageNW = Image.open(NullFile)
                
            try:            
                ImageNE = Image.open(FileNE)
            except IOError:
                ImageNE = Image.open(NullFile)
    
            try:            
                ImageSW = Image.open(FileSW)
            except IOError:
                ImageSW = Image.open(NullFile)
    
            try:            
                ImageSE = Image.open(FileSE)
            except IOError:
                ImageSE = Image.open(NullFile)        
    
            NewImage = Image.new("RGB", (256, 256) )
            NewImage.paste(ImageNW.resize((128,128), Image.ANTIALIAS), (0,0))
            NewImage.paste(ImageNE.resize((128,128), Image.ANTIALIAS), (128,0))
            NewImage.paste(ImageSW.resize((128,128), Image.ANTIALIAS), (0,128))
            NewImage.paste(ImageSE.resize((128,128), Image.ANTIALIAS), (128,128))
                    
            OutputFile = makeFilename(XIndex/2, YIndex/2, CurrentZoom - 1)
            NewImage.save(OutputFile)
            
            print CurrentZoom, XIndex, YIndex
    
    
#OutputFilename = makeFilename(1, 2, 3)
#print OutputFilename