mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 13:03:39 +08:00
FIX: optimize uploaded images using lossy but very fast compression
This commit is contained in:
parent
14a9a98c5b
commit
61d85206ee
8
.image_optim.yml
Normal file
8
.image_optim.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
skip_missing_workers: true
|
||||
allow_lossy: true
|
||||
advpng: false
|
||||
optipng: false
|
||||
pngcrush: false
|
||||
pngout: false
|
||||
pngquant:
|
||||
quality: !ruby/range 10..90
|
|
@ -74,18 +74,24 @@ class Upload < ActiveRecord::Base
|
|||
upload.url = ""
|
||||
upload.origin = options[:origin][0...1000] if options[:origin]
|
||||
|
||||
# deal with width & height for images
|
||||
upload = resize_image(filename, file, upload) if FileHelper.is_image?(filename)
|
||||
if FileHelper.is_image?(filename)
|
||||
# deal with width & height for images
|
||||
upload = resize_image(filename, file, upload)
|
||||
# optimize image
|
||||
ImageOptim.new.optimize_image!(file.path) rescue nil
|
||||
end
|
||||
|
||||
return upload unless upload.save
|
||||
|
||||
# store the file and update its url
|
||||
url = Discourse.store.store_upload(file, upload, options[:content_type])
|
||||
if url.present?
|
||||
upload.url = url
|
||||
upload.save
|
||||
else
|
||||
upload.errors.add(:url, I18n.t("upload.store_failure", { upload_id: upload.id, user_id: user_id }))
|
||||
File.open(file.path) do |f|
|
||||
url = Discourse.store.store_upload(f, upload, options[:content_type])
|
||||
if url.present?
|
||||
upload.url = url
|
||||
upload.save
|
||||
else
|
||||
upload.errors.add(:url, I18n.t("upload.store_failure", { upload_id: upload.id, user_id: user_id }))
|
||||
end
|
||||
end
|
||||
|
||||
# return the uploaded file
|
||||
|
|
Loading…
Reference in New Issue
Block a user