Skip to content

Instantly share code, notes, and snippets.

@derekphilipau
Created April 17, 2020 03:16
Show Gist options
  • Save derekphilipau/41635530d777531b9264136a47b7f43c to your computer and use it in GitHub Desktop.
Save derekphilipau/41635530d777531b9264136a47b7f43c to your computer and use it in GitHub Desktop.
small hack to rename a file based on its dhash hex value
import dhash
from PIL import Image
import shutil
import os
path1 = "images/"
path2 = "out/"
listing = os.listdir(path1)
for file in listing:
im = Image.open(path1 + file)
row, col = dhash.dhash_row_col(im)
shutil.copy(path1 + file, path2 + dhash.format_hex(row, col) + ".jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment