mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
optimize screenshots and thumbnails, slight thumbnail quality reduction
This commit is contained in:
parent
841779a36c
commit
e821410d84
5 changed files with 31 additions and 3 deletions
2
Gemfile
2
Gemfile
|
@ -43,6 +43,8 @@ gem 'acme-client'
|
||||||
gem 'http'
|
gem 'http'
|
||||||
gem 'htmlentities'
|
gem 'htmlentities'
|
||||||
gem 'rinku'
|
gem 'rinku'
|
||||||
|
gem 'image_optim'
|
||||||
|
gem 'image_optim_pack'
|
||||||
|
|
||||||
platform :mri, :rbx do
|
platform :mri, :rbx do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
16
Gemfile.lock
16
Gemfile.lock
|
@ -65,6 +65,7 @@ GEM
|
||||||
unf (>= 0.0.5, < 1.0.0)
|
unf (>= 0.0.5, < 1.0.0)
|
||||||
drydock (0.6.9)
|
drydock (0.6.9)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
|
exifr (1.2.5)
|
||||||
fabrication (2.15.0)
|
fabrication (2.15.0)
|
||||||
faker (1.6.3)
|
faker (1.6.3)
|
||||||
i18n (~> 0.5)
|
i18n (~> 0.5)
|
||||||
|
@ -75,6 +76,7 @@ GEM
|
||||||
ffi (>= 1.0.0)
|
ffi (>= 1.0.0)
|
||||||
rake
|
rake
|
||||||
filesize (0.1.1)
|
filesize (0.1.1)
|
||||||
|
fspath (3.0.1)
|
||||||
gandi (2.1.3)
|
gandi (2.1.3)
|
||||||
hashie
|
hashie
|
||||||
geoip (1.6.1)
|
geoip (1.6.1)
|
||||||
|
@ -95,6 +97,17 @@ GEM
|
||||||
http-form_data (1.0.1)
|
http-form_data (1.0.1)
|
||||||
http_parser.rb (0.6.0)
|
http_parser.rb (0.6.0)
|
||||||
i18n (0.7.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)
|
io-extra (1.2.8)
|
||||||
jimson-temp (0.9.5)
|
jimson-temp (0.9.5)
|
||||||
blankslate (>= 3.1.2)
|
blankslate (>= 3.1.2)
|
||||||
|
@ -141,6 +154,7 @@ GEM
|
||||||
cliver (~> 0.3.1)
|
cliver (~> 0.3.1)
|
||||||
websocket-driver (>= 0.2.0)
|
websocket-driver (>= 0.2.0)
|
||||||
posix-spawn (0.3.11)
|
posix-spawn (0.3.11)
|
||||||
|
progress (3.2.2)
|
||||||
pry (0.10.3)
|
pry (0.10.3)
|
||||||
coderay (~> 1.1.0)
|
coderay (~> 1.1.0)
|
||||||
method_source (~> 0.8.1)
|
method_source (~> 0.8.1)
|
||||||
|
@ -277,6 +291,8 @@ DEPENDENCIES
|
||||||
hoe (= 3.14.2)
|
hoe (= 3.14.2)
|
||||||
htmlentities
|
htmlentities
|
||||||
http
|
http
|
||||||
|
image_optim
|
||||||
|
image_optim_pack
|
||||||
io-extra
|
io-extra
|
||||||
jdbc-postgres
|
jdbc-postgres
|
||||||
jruby-openssl
|
jruby-openssl
|
||||||
|
|
|
@ -152,3 +152,5 @@ end
|
||||||
gandi_opts = {}
|
gandi_opts = {}
|
||||||
gandi_opts[:env] = :test # unless ENV['RACK_ENV'] == 'production'
|
gandi_opts[:env] = :test # unless ENV['RACK_ENV'] == 'production'
|
||||||
$gandi = Gandi::Session.new $config['gandi_api_key'], gandi_opts
|
$gandi = Gandi::Session.new $config['gandi_api_key'], gandi_opts
|
||||||
|
|
||||||
|
$image_optim = ImageOptim.new pngout: false, svgo: false
|
||||||
|
|
|
@ -62,10 +62,15 @@ class ScreenshotWorker
|
||||||
else
|
else
|
||||||
new_img = img.scale width, height
|
new_img = img.scale width, height
|
||||||
end
|
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
|
self.quality = 90
|
||||||
}
|
}
|
||||||
|
|
||||||
new_img.destroy!
|
new_img.destroy!
|
||||||
|
$image_optim.optimize_image! full_screenshot_path
|
||||||
end
|
end
|
||||||
|
|
||||||
img.destroy!
|
img.destroy!
|
||||||
|
|
|
@ -26,9 +26,12 @@ class ThumbnailWorker
|
||||||
|
|
||||||
save_ext = format.match(Site::LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
|
save_ext = format.match(Site::LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
|
||||||
|
|
||||||
resimg.write(File.join(user_thumbnails_path, "#{path}.#{res}.#{save_ext}")) {
|
full_thumbnail_path = File.join(user_thumbnails_path, "#{path}.#{res}.#{save_ext}")
|
||||||
self.quality = 90
|
|
||||||
|
resimg.write(full_thumbnail_path) {
|
||||||
|
self.quality = 75
|
||||||
}
|
}
|
||||||
|
$image_optim.optimize_image! full_thumbnail_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue