Skip to content

Instantly share code, notes, and snippets.

@honsa
Last active June 29, 2018 14:16
Show Gist options
  • Save honsa/bf972693bc1452d42acc1d87d0ce18e1 to your computer and use it in GitHub Desktop.
Save honsa/bf972693bc1452d42acc1d87d0ce18e1 to your computer and use it in GitHub Desktop.
thumbor optimizer support for guetzli
#!/usr/bin/python
# -*- coding: utf-8 -*-
# thumbor imaging service
# https://github.com/thumbor/thumbor/wiki
#guetzli compression for thumbor
#https://gist.github.com/honsa/bf972693bc1452d42acc1d87d0ce18e1
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2018 globo.com [email protected]
import os
import subprocess
from subprocess import Popen, PIPE
from thumbor.optimizers import BaseOptimizer
from thumbor.utils import logger
from os.path import exists
class Optimizer(BaseOptimizer):
def should_run(self, image_extension, buffer):
if image_extension in ['.jpg', '.jpeg']:
if not exists(self.context.config.GUETZLI_PATH):
logger.warn(
'guetzli optimizer enabled but binary GUETZLI_PATH does not exist')
return False
return True
return False
def optimize(self, buffer, input_file, output_file):
command = self.context.config.GUETZLI_PATH + ' --quality 84' + ' --verbose ' + input_file + ' ' + output_file
os.system(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment