18
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonでPILを使用してExifから欲しいデータだけを抜き出す

Posted at

お前の写真は偽物だ!
という疑念がわいた時、たいていスマホでとった写真にはExifデータがあるはず。
Twitterなどで時系列が疑わしい写真を解析したり、
そういうことに色々使えるんじゃないかなとか。

pilexif.py

#!/user/bin/env python
# -*- coding: utf-8 -*-
import sys
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS

def get_exif(file,field):

	img = Image.open(file)
	exif = img._getexif()

	
	exif_data = []
	for id, value in exif.items():
		if TAGS.get(id) == field:
			tag = TAGS.get(id, id),value
			exif_data.extend(tag)

	
	return exif_data

my_img = "sample.jpg"
print get_exif(my_img,"DateTimeOriginal")

最後のprintで渡している箇所を書き換えると特定データのみ拾える。

print get_exif(my_img,"DataTime")
print get_exif(my_img,"Model")

などなど。

18
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?