mirror of
https://github.com/neocities/neocities.git
synced 2025-08-05 01:01:30 +02:00
fixes for thumbnail worker
This commit is contained in:
parent
3e4e85ceee
commit
0aca6b3328
6 changed files with 48 additions and 21 deletions
|
@ -1,25 +1,26 @@
|
|||
require 'RMagick'
|
||||
|
||||
class ThumbnailWorker
|
||||
THUMBNAILS_PATH = File.join DIR_ROOT, 'public', 'site_thumbnails'
|
||||
THUMBNAILS_PATH = Site::THUMBNAILS_ROOT
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: :thumbnails, retry: 3, backtrace: true
|
||||
|
||||
def perform(username, filename)
|
||||
def perform(username, path)
|
||||
img_list = Magick::ImageList.new
|
||||
img_list.from_blob File.read(File.join(Site::SITE_FILES_ROOT, username, filename))
|
||||
img_list.from_blob File.read(File.join(Site::SITE_FILES_ROOT, username, path))
|
||||
img = img_list.first
|
||||
|
||||
user_thumbnails_path = File.join THUMBNAILS_PATH, username
|
||||
FileUtils.mkdir_p user_thumbnails_path
|
||||
FileUtils.mkdir_p File.join(user_thumbnails_path, File.dirname(path))
|
||||
|
||||
Site::THUMBNAIL_RESOLUTIONS.each do |res|
|
||||
resimg = img.resize_to_fit(*res.split('x').collect {|r| r.to_i})
|
||||
format = File.extname(filename).gsub('.', '')
|
||||
format = File.extname(path).gsub('.', '')
|
||||
|
||||
save_ext = format.match(Site::LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
|
||||
|
||||
resimg.write(File.join(user_thumbnails_path, "#{filename}.#{res}.#{save_ext}")) {
|
||||
resimg.write(File.join(user_thumbnails_path, "#{path}.#{res}.#{save_ext}")) {
|
||||
self.quality = 90
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue