Skip to content

Instantly share code, notes, and snippets.

@shm007g
Last active September 17, 2021 14:16
Show Gist options
  • Save shm007g/965803be4bce4b0ce0c4b3262566f176 to your computer and use it in GitHub Desktop.
Save shm007g/965803be4bce4b0ce0c4b3262566f176 to your computer and use it in GitHub Desktop.
照片打时间戳脚本
import cv2
def mark_photo(text, path, output_path=None):
img = cv2.imread(path)
height, width = img.shape[:2]
font = cv2.FONT_HERSHEY_SCRIPT_COMPLEX
img = cv2.putText(img, text, (width - 500, height - 80), font, 1.2, (0, 255, 255))
if output_path is None:
path_parts = path.split('.')
output_path = '.'.join(path_parts[:-1]) + '_Marked.' + path_parts[-1]
cv2.imwrite(output_path, img)
text = '2020.08.15 08:47'
path = '/Users/lovely/Downloads/2020_08_15_08_47_IMG_1010.jpg'
mark_photo(text, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment