And document EXIF modification for future self.
for k, v in im._getexif().items()
if k in PIL.ExifTags.TAGS and len(str(v)) < 256
}
- # Can't use just *exif['ExposureTime'] on Py3.4
- caption = "F{}, {}/{} s, ISO {}".format(float(exif['FNumber'][0])/float(exif['FNumber'][1]), exif['ExposureTime'][0], exif['ExposureTime'][1], exif['ISOSpeedRatings'])
+
+ # Not all info might be present
+ caption = []
+ if 'FNumber' in exif:
+ caption += ["F{}".format(float(float(exif['FNumber'][0])/float(exif['FNumber'][1])))]
+ if 'ExposureTime' in exif:
+ caption += ["{}/{} s".format(exif['ExposureTime'][0], exif['ExposureTime'][1])]
+ if 'ISOSpeedRatings' in exif:
+ caption += ["ISO {}".format(exif['ISOSpeedRatings'])]
+ caption = ', '.join(caption)
# It's not (e.g. a PNG file), empty caption
else: caption = ""
</figure>
</div>
</div>
-<p>Image grid with a PNG file:</p>
+<p>Image grid with a PNG file and a JPEG with sparse EXIF data:</p>
<div class="m-imagegrid m-container-inflate">
<div>
-<figure style="width: 100.000%">
+<figure style="width: 70.588%">
<a href="./tiny.png"><img src="./tiny.png" /><div>
</div>
</a>
</figure>
+<figure style="width: 29.412%">
+<a href="./sparseexif.jpg"><img src="./sparseexif.jpg" /><figcaption>F2.8</figcaption>
+</a>
+</figure>
</div>
</div>
<!-- /content -->
{filename}/flowers.jpg
{filename}/ship.jpg
-Image grid with a PNG file:
+Image grid with a PNG file and a JPEG with sparse EXIF data:
.. image-grid::
{filename}/tiny.png
+ {filename}/sparseexif.jpg
def test(self):
self.run_pelican({
'PLUGINS': ['m.htmlsanity', 'm.images'],
- 'STATIC_PATHS': ['tiny.png', 'ship.jpg', 'flowers.jpg']
+ 'STATIC_PATHS': ['tiny.png', 'ship.jpg', 'flowers.jpg', 'sparseexif.jpg']
})
+ #
+ # Modifying EXIF in files for testing:
+ #
+ # # Prints out all EXIF info
+ # identify -format '%[EXIF:*]' file.jpg
+ #
+ # # Removes *everything* and adds a new value (order is important)
+ # exiftool -all= -exif:FNumber=28/10 file.jpg
+ #
+
self.assertEqual(*self.actual_expected_contents('page.html'))