Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Arthur thebostik

View GitHub Profile
@thebostik
thebostik / dynamic_quality.py
Created May 30, 2017
Python Dynamic Image Quality Example
View dynamic_quality.py
import cStringIO
import PIL.Image
from ssim import compute_ssim
def get_ssim_at_quality(photo, quality):
"""Return the ssim for this JPEG image saved at the specified quality"""
ssim_photo = cStringIO.StringIO()
# optimize is omitted here as it doesn't affect
# quality but requires additional memory and cpu
@thebostik
thebostik / Dockerfile
Created May 30, 2017
Mozjpeg + Pillow Dockerfile
View Dockerfile
FROM ubuntu:xenial
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \
# build tools
nasm \
build-essential \
autoconf \
automake \
libtool \
@thebostik
thebostik / starting_point.py
Created May 30, 2017
Photo Upload Starting Point
View starting_point.py
# do a typical thumbnail, preserving aspect ratio
new_photo = photo.copy()
new_photo.thumbnail(
(width, height),
resample=PIL.Image.ANTIALIAS,
)
thumbfile = cStringIO.StringIO()
save_args = {'format': format}
if format == 'JPEG':
save_args['quality'] = 85
You can’t perform that action at this time.