Move new_image function to helper

This commit is contained in:
Chris Pham
2018-02-03 13:50:32 -08:00
parent 06c605ebd5
commit e65d4e5067
2 changed files with 9 additions and 6 deletions

View File

@@ -1,3 +1,8 @@
import PIL.Image
class MapHelper(object):
def __init__(self):
return
def new_image(self, width, height):
return PIL.Image.new('RGBA', (width, height))

View File

@@ -26,9 +26,9 @@ import urllib2
from io import StringIO, BytesIO
import os
import time
import PIL.Image
import PIL.ImageDraw
import signing
import MapHelper
#####################################
# Constants
@@ -55,6 +55,7 @@ class GMapsStitcher(object):
def __init__(self, width, height,
latitude, longitude, zoom,
maptype, radius_meters=None, num_tiles=4, debug=False):
helper = MapHelper.MapHelper()
self.latitude = latitude
self.longitude = longitude
self.start_latitude = latitude
@@ -65,7 +66,7 @@ class GMapsStitcher(object):
self.maptype = maptype
self.radius_meters = radius_meters
self.num_tiles = num_tiles
self.display_image = self._new_image(width, height)
self.display_image = helper.new_image(width, height)
self.debug = debug
# Get the big image here
@@ -87,9 +88,6 @@ class GMapsStitcher(object):
string_builder += "LatLong of Southeast Corner: %4f, %4f\n" % (self.southeast)
return string_builder
def _new_image(self, width, height):
return PIL.Image.new('RGBA', (width, height))
def _fast_round(self, value, precision):
return int(value * 10 ** precision) / 10. ** precision
@@ -155,7 +153,7 @@ class GMapsStitcher(object):
sin_lat = math.sin(math.radians(self.latitude))
lat_pixels = _EARTHPIX - _PIXRAD * math.log((1+sin_lat)/(1-sin_lat))/2
self.big_size = self.num_tiles * _TILESIZE
big_image = self._new_image(self.big_size, self.big_size)
big_image = self.helper.new_image(self.big_size, self.big_size)
for j in range(self.num_tiles):
lon = self._pixels_to_lon(j, lon_pixels)