Skip to content

Instantly share code, notes, and snippets.

@xiwcx
Created March 3, 2019 02:17
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 xiwcx/6397cc2112615d5556f9b5e4616b53ab to your computer and use it in GitHub Desktop.
Save xiwcx/6397cc2112615d5556f9b5e4616b53ab to your computer and use it in GitHub Desktop.
pillow examples
import os, sys
from PIL import Image, ImageOps
infile = "example.jpg"
square = os.path.splitext(infile)[0] + ".square.jpg"
webp = os.path.splitext(infile)[0] + ".webp"
size = (1000, 1000)
im = Image.open(infile)
square_image = ImageOps.fit(im, size, Image.ANTIALIAS)
square_image = square_image.convert(mode="RGB")
webp_image = im;
square_image.save(square, quality=70, optimize=True, progressive=True)
webp_image.save(webp, quality=70, method=6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment