mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-26 07:19:25 -05:00
Losslessly optimize JPEGs.
Disabled by default in example.ini. Install jpegoptim or an equivalent and set the configuration properly.
This commit is contained in:
@@ -349,6 +349,8 @@ translator_password =
|
||||
takedown_sr = _takedowns
|
||||
# png compressor
|
||||
png_optimizer = /usr/bin/env optipng
|
||||
# jpeg compressor
|
||||
jpeg_optimizer =
|
||||
|
||||
# -- search --
|
||||
# where is solor?
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
# CondeNet, Inc. All Rights Reserved.
|
||||
################################################################################
|
||||
|
||||
import subprocess
|
||||
|
||||
from pylons import g, config
|
||||
|
||||
from r2.models.link import Link
|
||||
@@ -50,6 +52,13 @@ log = g.log
|
||||
MEDIA_FILENAME_LENGTH = 12
|
||||
|
||||
|
||||
def optimize_jpeg(filename, optimizer):
|
||||
if optimizer:
|
||||
with open(os.path.devnull, 'w') as devnull:
|
||||
subprocess.check_call((optimizer, filename),
|
||||
stdout=devnull)
|
||||
|
||||
|
||||
def thumbnail_url(link):
|
||||
"""Given a link, returns the url for its thumbnail based on its fullname"""
|
||||
if link.has_thumbnail:
|
||||
@@ -116,6 +125,8 @@ def upload_media(image, never_expire=True, file_type='.jpg'):
|
||||
|
||||
if file_type == ".png":
|
||||
optimize_png(f.name, g.png_optimizer)
|
||||
elif file_type == ".jpg":
|
||||
optimize_jpeg(f.name, g.jpeg_optimizer)
|
||||
contents = open(f.name).read()
|
||||
file_name = get_filename_from_content(contents)
|
||||
if g.media_store == "s3":
|
||||
|
||||
Reference in New Issue
Block a user