# Read original picture from StdIn '-auto-orient', # Detect picture orientation from metadata '-thumbnail', '{}x{}{}'.format(width, height, mode), # Thumbnail size '-extent', '{}x{}'.format(width, height), # Fill if original picture i smaller than thumbnail '-gravity', 'Center', # Extend (fill) from the thumbnail middle '-unsharp',' 0x.5', # Un-sharpen slightly to improve small thumbnails '-quality', '80%', # Thumbnail JPG quality '{}:-'.format(format), # Write thumbnail with `format` to StdOut ] p = Popen(cmd, stdout=PIPE, stdin=PIPE) thumbnail = p.communicate(input=image)[0] https://github.com/Schweigi/thumbnail-service