Skip to content

Instantly share code, notes, and snippets.

@Omochin
Last active May 26, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Omochin/94e47189a00b77ca0f73d0c5a1b59953 to your computer and use it in GitHub Desktop.
Save Omochin/94e47189a00b77ca0f73d0c5a1b59953 to your computer and use it in GitHub Desktop.
Need 'pip install pillow'
import os
from PIL import Image
def main():
input_path = './a'
output_path = './b'
quality = 30
if not os.path.isdir(output_path):
os.mkdir(output_path)
for filename in os.listdir(input_path):
base, ext = os.path.splitext(filename)
if ext == '.png':
save_path = os.path.join(output_path, base + '.jpg')
input_image = Image.open(os.path.join(input_path, filename))
input_image.convert('RGB').save(save_path, quality=quality)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment