Skip to content

Instantly share code, notes, and snippets.

@amirshim
Created June 24, 2010 21:36
Show Gist options
  • Save amirshim/452022 to your computer and use it in GitHub Desktop.
Save amirshim/452022 to your computer and use it in GitHub Desktop.
# for GAE - tries get the image size... not too efficient...
# could throw lots of different exceptions, including DeadlineExceededError
class ImageBlobHelper(object):
@staticmethod
def TryGetWidthHeight(blobinfo, read_increments = 32768):
total_read = 0
blob_key = blobinfo.key();
data = ''
while total_read < blobinfo.size:
data_read = blobstore.fetch_data(blob_key, total_read, total_read+read_increments)
total_read += len(data_read)
data += data_read
try:
imgtemp = images.Image(image_data=data)
res = (imgtemp.width, imgtemp.height)
return res
except images.BadImageError, images.NotImageError:
pass
raise images.BadImageError("Unable to get width and height")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment