2

The examples I have found for using pillow to access EXIF metadata for an image make use of the protected member _getexif() of PIL.Image. Pylint will complain about this with the following warning:

[W0212(protected-access), functionname] Access to a protected member _getexif of a client class

Is there a way to get at the EXIF data for an Image without going through a protected member?

Diado
  • 2,229
  • 3
  • 18
  • 21
D.A.
  • 33
  • 8

1 Answers1

3

_getexif() is underscored because they don't want to commit to it always working the way it does now - the code says "This method is highly experimental, and is likely to be replaced with something better in a future version." Although, as far as I know, it's said that in PIL for ages.

So your choices are:

  • suppress the lint warning
  • get the raw (unparsed) exif data with i.info.get('exif') and parse it yourself, possibly with code ripped out of Pillow
  • use a supported exif library like ExifRead

edit: really "don't want to commit to it always working the way it does now" is underselling it a bit - _getexif() is for the library's own (very limited) internal use, and they recognise that parsing real exifs found in the wild, and giving a reliable result for all (even the weird ones) is a more significant undertaking than they're willing to sign up for.

Finlay McWalter
  • 1,222
  • 1
  • 10
  • 12
  • Unfortunately, Stack Overflow references use of `_getexif()` in ["In Python, how do I read the exif data for an image?"](https://stackoverflow.com/questions/4764932/in-python-how-do-i-read-the-exif-data-for-an-image#4765242) Using ExifRead seems to be the more robust approach despite the accepted best answer to the other post. – D.A. Jan 25 '18 at 14:59
  • It's not that `_getexif()` is *wrong*, it's that it's a bit risky (risk that it changes, risk that it's removed, and risk because it's not a very well supported or documented feature). I'm not convinced that most people care about most of the data you get from EXIF anyway. Beyond time-and-place taken, and maybe exposure/shutter info, it's fairly dull and esoteric stuff. – Finlay McWalter Jan 25 '18 at 15:12
  • _getexif has been labelled as experimental ever since it was first implemented in PIL 1.1.4 in 2003! http://effbot.org/zone/pil-changes-114.htm – Hugo Jan 27 '18 at 01:40