Created
June 24, 2010 21:36
-
-
Save amirshim/452022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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