def get_highres_img(uid,fieldid,fieldmaxlat,fieldminlat,fieldmaxlong,fieldminlong): import urllib.parse import urllib.request from io import StringIO from PIL import Image from math import log, exp, tan, atan, pi, ceil from latlontopixels import latlontopixels from pixelstolatlon import pixelstolatlon import io import math import os from getmapstaticcoords import getmapstaticcoords from sign_url import sign_url import time zoom = 18 # be careful not to get too many images! scale = 2 tile_pixels = 256 upperleft = str(fieldminlat)+','+str(fieldmaxlong) lowerright= str(fieldmaxlat)+','+str(fieldminlong) print(upperleft) print(lowerright) centerlat = (fieldminlat+fieldmaxlat)/2 centerlong = (fieldminlong+fieldmaxlong)/2 position = str(centerlat)+','+str(centerlong) longs_per_tile = 0.001 field_lat_len = abs(fieldmaxlat-fieldminlat) field_long_len = abs(fieldmaxlong - fieldminlong) width = round(0.8*tile_pixels*field_lat_len/longs_per_tile) height = round(0.8*tile_pixels*field_long_len/longs_per_tile) templateName = 'template.png' sizeimg = str(height) + 'x' + str(width) print(sizeimg) urlparams = urllib.parse.urlencode({'center': position, 'zoom': str(zoom), 'size': sizeimg, 'maptype': 'satellite', 'sensor': 'false', 'scale': scale}) unsigned_url = 'https://maps.googleapis.com/maps/api/staticmap?' + urlparams+'&key=AIzaSyDnM_35WfYwhJmTSPxyyiMIcYte65mPitc' print(unsigned_url) #url = sign_url(unsigned_url,'JhMz6qX72pOeIplGof3xDUsiHuA=') #print(url) f=urllib.request.urlopen(unsigned_url) image_file = io.BytesIO(f.read()) im=Image.open(image_file) img_name = uid+'/highres_'+str(fieldid)+'.png' im = im.resize((height,width)) im.save(img_name,"PNG") return templateName