2015-05-25 11:59:00 -04:00
|
|
|
module Jobs
|
|
|
|
|
|
|
|
class CreateThumbnails < Jobs::Base
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
upload_id = args[:upload_id]
|
|
|
|
type = args[:type]
|
|
|
|
|
|
|
|
raise Discourse::InvalidParameters.new(:upload_id) if upload_id.blank?
|
|
|
|
raise Discourse::InvalidParameters.new(:type) if type.blank?
|
|
|
|
|
|
|
|
# only need to generate thumbnails for avatars
|
|
|
|
return if type != "avatar"
|
|
|
|
|
|
|
|
upload = Upload.find(upload_id)
|
|
|
|
|
|
|
|
self.send("create_thumbnails_for_#{type}", upload)
|
|
|
|
end
|
|
|
|
|
2015-05-27 19:48:07 -04:00
|
|
|
PIXEL_RATIOS ||= [1, 2, 3]
|
2015-05-25 11:59:00 -04:00
|
|
|
|
|
|
|
def create_thumbnails_for_avatar(upload)
|
2015-05-27 19:48:07 -04:00
|
|
|
PIXEL_RATIOS.each do |pixel_ratio|
|
2015-05-25 11:59:00 -04:00
|
|
|
Discourse.avatar_sizes.each do |size|
|
2015-05-27 19:48:07 -04:00
|
|
|
size *= pixel_ratio
|
|
|
|
OptimizedImage.create_for(upload, max, max, allow_animation: SiteSetting.allow_animated_avatars)
|
2015-05-25 11:59:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|