Image exif data in google app engine

2019-04-29 11:17发布

In google app engine dev environment I cannot get exif data. I followed guide from here https://developers.google.com/appengine/docs/python/images/imageclass

I have done following in the code

def getResizedImage(self, image, imagemaxWidth, imagemaxHeight):
    img = images.Image(image_data=image)
    logging.error(img.get_original_metadata())

I only get None. the img object is fine as I can perform img.resize etc. I need to get Exif info.

UPDATE: By doing this I was able to get metadata,

def getResizedImage(self, image, imagemaxWidth, imagemaxHeight):
    img = images.Image(image_data=image)
    img.rotate(0)
    img.execute_transforms()
    logging.error(img.get_original_metadata())

Like explained in documentation I got very 'limited' set more precisely this

{u'ImageLength': 480, u'ImageWidth': 640}

Apparently you get much bigger set in real environment, I have no idea why this cant be the feature of dev env though. It is quite frustrating. As long as I can get pyexiv2 level exif I am okay but if it is just using PIL that is not good enough. Currently PIL provides way little exif information.

2条回答
爷的心禁止访问
2楼-- · 2019-04-29 11:51

The dev environment uses PIL which explains what you see. The production environment does not use PIL and will give you the majority of the tags that are in the image.

查看更多
爷、活的狠高调
3楼-- · 2019-04-29 12:03

Taken from the docs for get_original_metadata

Returns:
  dict with string keys. If execute_transform was called with parse_metadata
  being True, this dictionary contains information about various properties
  of the original image, such as dimensions, color profile, and properties
  from EXIF.
  Even if parse_metadata was False or the images did not have any metadata,
  the dictionary will contain a limited set of metadata, at least
  'ImageWidth' and 'ImageLength', corresponding to the dimensions of the
  original image.
  It will return None, if it is called before a successful
  execute_transfrom.

You want to pass parse_metadata=True to execute_transform in order to get more metadata including the exif data.

Also The bottom note about it returning None explains why you had to call execute_transforms in order to get anything back

查看更多
登录 后发表回答