Created
August 28, 2019 06:47
-
-
Save atul-chaudhary/d5d95516a557b7411f379a3503bb1920 to your computer and use it in GitHub Desktop.
Python Script to compress the size of all image inside a folder without the changing the dimension of the image and save them to other folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#PIL (python image library) make sure you have PIL installed, otherwise install it from here my typing commnad ->pip install Pillow | |
#if you have PIL already you are good to go. | |
import os | |
from PIL import Image | |
def main(): | |
select_folder='C:\\Users\\atulc\\Downloads\\The Best Cars HD Wallpapers' #my first folder or source folder | |
dest_folder='D:\\my walls\\cars' #my destination folder | |
for image_path in os.listdir(select_folder): | |
print(image_path) | |
input_path=os.path.join(select_folder,image_path) | |
img=Image.open(input_path) | |
print(input_path) | |
new_image=img.resize(img.size,Image.ANTIALIAS) | |
dest_path=os.path.join(dest_folder,'cmpr'+image_path) #cmpr represent the compressed image you can chnage it to other name | |
new_image.save(dest_path) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment