Skip to content

Commit

Permalink
Added support for local bitmaps by filename or URL
Browse files Browse the repository at this point in the history
  • Loading branch information
migurski committed Sep 18, 2012
1 parent de9ff2d commit 0fb152e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion TileStache/Sandwich.py
Expand Up @@ -113,6 +113,8 @@
"""
from re import search
from StringIO import StringIO
from urlparse import urljoin
from urllib import urlopen

from . import Core

Expand Down Expand Up @@ -186,7 +188,10 @@ def draw_stack(stack, coord, config, tiles):
raise Core.KnownUnknown("You can't specify src, color and mask together in a Sandwich Layer: %s, %s, %s" % (repr(source_name), repr(color_name), repr(mask_name)))

if source_name and source_name not in tiles:
tiles[source_name] = layer_bitmap(config.layers[source_name], coord)
if source_name in config.layers:
tiles[source_name] = layer_bitmap(config.layers[source_name], coord)
else:
tiles[source_name] = local_bitmap(source_name, config, coord)

if mask_name and mask_name not in tiles:
tiles[mask_name] = layer_bitmap(config.layers[mask_name], coord)
Expand Down Expand Up @@ -229,6 +234,15 @@ def draw_stack(stack, coord, config, tiles):

return rendered

def local_bitmap(source, config, coord):
""" Return Blit.Bitmap representation of a raw image.
"""
address = urljoin(config.dirpath, source)
bytes = urlopen(address).read()
image = Image.open(StringIO(bytes)).convert('RGBA')

return Blit.Bitmap(image)

def layer_bitmap(layer, coord):
""" Return Blit.Bitmap representation of tile from a given layer.
Expand Down

0 comments on commit 0fb152e

Please sign in to comment.