optimize screenshots and thumbnails, slight thumbnail quality reduction

This commit is contained in:
Kyle Drake 2016-12-29 17:09:01 -06:00
parent 841779a36c
commit e821410d84
5 changed files with 31 additions and 3 deletions

View file

@ -43,6 +43,8 @@ gem 'acme-client'
gem 'http'
gem 'htmlentities'
gem 'rinku'
gem 'image_optim'
gem 'image_optim_pack'
platform :mri, :rbx do
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic

View file

@ -65,6 +65,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
drydock (0.6.9)
erubis (2.7.0)
exifr (1.2.5)
fabrication (2.15.0)
faker (1.6.3)
i18n (~> 0.5)
@ -75,6 +76,7 @@ GEM
ffi (>= 1.0.0)
rake
filesize (0.1.1)
fspath (3.0.1)
gandi (2.1.3)
hashie
geoip (1.6.1)
@ -95,6 +97,17 @@ GEM
http-form_data (1.0.1)
http_parser.rb (0.6.0)
i18n (0.7.0)
image_optim (0.24.1)
exifr (~> 1.2, >= 1.2.2)
fspath (~> 3.0)
image_size (~> 1.5)
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
image_optim_pack (0.3.0.20161206)
fspath (>= 2.1, < 4)
image_optim (~> 0.19)
image_size (1.5.0)
in_threads (1.3.1)
io-extra (1.2.8)
jimson-temp (0.9.5)
blankslate (>= 3.1.2)
@ -141,6 +154,7 @@ GEM
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
posix-spawn (0.3.11)
progress (3.2.2)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -277,6 +291,8 @@ DEPENDENCIES
hoe (= 3.14.2)
htmlentities
http
image_optim
image_optim_pack
io-extra
jdbc-postgres
jruby-openssl

View file

@ -152,3 +152,5 @@ end
gandi_opts = {}
gandi_opts[:env] = :test # unless ENV['RACK_ENV'] == 'production'
$gandi = Gandi::Session.new $config['gandi_api_key'], gandi_opts
$image_optim = ImageOptim.new pngout: false, svgo: false

View file

@ -62,10 +62,15 @@ class ScreenshotWorker
else
new_img = img.scale width, height
end
new_img.write(File.join(user_screenshots_path, "#{path}.#{res}.jpg")) {
full_screenshot_path = File.join(user_screenshots_path, "#{path}.#{res}.jpg")
new_img.write(full_screenshot_path) {
self.quality = 90
}
new_img.destroy!
$image_optim.optimize_image! full_screenshot_path
end
img.destroy!

View file

@ -26,9 +26,12 @@ class ThumbnailWorker
save_ext = format.match(Site::LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
resimg.write(File.join(user_thumbnails_path, "#{path}.#{res}.#{save_ext}")) {
self.quality = 90
full_thumbnail_path = File.join(user_thumbnails_path, "#{path}.#{res}.#{save_ext}")
resimg.write(full_thumbnail_path) {
self.quality = 75
}
$image_optim.optimize_image! full_thumbnail_path
end
end
end