4
6

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.

Python3で同じ画像ファイルを探す方法

Posted at

画像ファイルをmd5のハッシュにして、比較するという簡単な方法です。

imgsフォルダに入っている画像達で、hoge.jpgと全く同じものが存在するか確認する方法です

import hashlib
from glob import glob
target = open("hoge.jpg", "rb").read()
target_md5 = hashlib.md5(target).hexdigest() 

files = glob("imgs/*.jpg")

for file in files:
    with open(file, 'rb') as image:
        image_data = image.read()
        image_md5 = hashlib.md5(image_data).hexdigest()
        if md5 == target:
            print("👀", end="")

結果

👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀
4
6
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
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?