python-bulk-images-resize.py 916 B

123456789101112131415161718192021222324252627282930313233343536
  1. import PIL
  2. import os
  3. import os.path
  4. from PIL import Image
  5. img_dir = r'C:/MyDocuments/roytuts/feature-images/temp/'
  6. print('Bulk images resizing started...')
  7. for img in os.listdir(img_dir):
  8. f_img = img_dir + img
  9. f, e = os.path.splitext(img_dir + img)
  10. img = Image.open(f_img)
  11. img = img.resize((1200, 628))
  12. #img.save(f + '_resized.jpg')
  13. img.save(f_img)
  14. print('Bulk images resizing finished...')
  15. #from PIL import Image
  16. #import os, sys
  17. #img_dir = "C:/MyDocuments/roytuts/feature-images/resized-2/"
  18. #dirs = os.listdir( img_dir )
  19. #def resize_bulk_images():
  20. # for img in dirs:
  21. # if os.path.isfile(img_dir + img):
  22. # im = Image.open(img_dir + img)
  23. # f, e = os.path.splitext(img_dir + img)
  24. # imResize = im.resize((1200, 628), Image.ANTIALIAS)
  25. # imResize.save(f + '_resized.jpg', 'JPEG', quality=90)
  26. #print('Bulk images resizing started...')
  27. #resize_bulk_images()
  28. #print('Bulk images resizing finished...')