This article mainly introduces Python's batch scale-down image script sharing. This article provides the implementation code directly. if you need it, you can refer to the picture below. it is too slow to use photoshop for over images, I want to write a simple batch processing in python. The simple function is to scale down the source image proportionally.
The code is as follows:
#-*-Coding: cp936 -*-
Import Image
Import glob, OS
# Image batch processing
Def timage ():
For files in glob. glob ('d :\\\ 1 \\\\ *. JPG '):
Filepath, filename = OS. path. split (files)
Filterame, exts = OS. path. splitext (filename)
# Output path
Opfile = r 'd: \\\\ 22 \\\\'
# Determine whether the opfile exists. if the opfile does not exist, it is created.
If (OS. path. isdir (opfile) = False ):
OS. mkdir (opfile)
Im = Image. open (files)
W, h = im. size
# Im_ss = im. resize (400,400 ))
# Im_ss = im. convert ('P ')
Im_ss = im. resize (int (w * 0.12), int (h * 0.12 )))
Im_ss.save(opfile?filterame='.jpg ')
If _ name __= = '_ main __':
Timage ()
Print 'Haha finished'