Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import os
  2.  
  3.  
  4. def is_valid_jpg(jpg_file):
  5.     with open(jpg_file, 'rb') as f:
  6.         f.seek(-2, 2)
  7.         buf = f.read()
  8.         return buf ==  b'\xff\xd9'
  9.  
  10. def is_valid_png(png_file):
  11.     with open(png_file, 'rb') as f:
  12.         f.seek(-2, 2)
  13.         buf = f.read()
  14.         return buf == b'\x60\x82'
  15.  
  16. for dirPath, dirNames, fileNames in os.walk("D:\long\Desktop\image\\"):
  17.     print (dirPath)
  18.     path =(dirPath+"\\")
  19.     for file in os.listdir(path):
  20.         pic_file = path + file
  21.         isJpg = is_valid_jpg(pic_file)
  22.         isPng = is_valid_png(pic_file)
  23.     print("jpeg : %s, png %s, file %s " % (isJpg, isPng, file))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement