diff options
Diffstat (limited to 'app/models/concerns/file_attachment.rb')
| -rw-r--r-- | app/models/concerns/file_attachment.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/concerns/file_attachment.rb b/app/models/concerns/file_attachment.rb index 0e99fa2..3c09456 100644 --- a/app/models/concerns/file_attachment.rb +++ b/app/models/concerns/file_attachment.rb | |||
| @@ -23,9 +23,10 @@ module FileAttachment | |||
| 23 | extend ActiveSupport::Concern | 23 | extend ActiveSupport::Concern |
| 24 | 24 | ||
| 25 | STYLES = { | 25 | STYLES = { |
| 26 | medium: { geometry: "300x300>", format: nil }, | 26 | medium: { args: ["-resize", "300x300>"] }, |
| 27 | thumb: { geometry: "100x100>", format: nil }, | 27 | thumb: { args: ["-resize", "100x100>"] }, |
| 28 | headline: { geometry: "460x250!", format: nil } | 28 | headline: { args: ["-resize", "460x250^", "-gravity", "center", "-extent", "460x250"] }, |
| 29 | large: { args: ["-resize", "1600x1600>"] } | ||
| 29 | }.freeze | 30 | }.freeze |
| 30 | 31 | ||
| 31 | IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze | 32 | IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze |
| @@ -80,7 +81,7 @@ module FileAttachment | |||
| 80 | STYLES.each do |style, options| | 81 | STYLES.each do |style, options| |
| 81 | dest_path = file_path(style) | 82 | dest_path = file_path(style) |
| 82 | FileUtils.mkdir_p(File.dirname(dest_path)) | 83 | FileUtils.mkdir_p(File.dirname(dest_path)) |
| 83 | system("magick", original_path, "-resize", options[:geometry], dest_path) | 84 | system("magick", original_path, *options[:args], dest_path) |
| 84 | end | 85 | end |
| 85 | end | 86 | end |
| 86 | 87 | ||
| @@ -105,7 +106,8 @@ module FileAttachment | |||
| 105 | end | 106 | end |
| 106 | 107 | ||
| 107 | def sanitize_filename(filename) | 108 | def sanitize_filename(filename) |
| 108 | File.basename(filename).gsub(/[^\w\.\-]/, '_') | 109 | name = File.basename(filename).unicode_normalize(:nfc) |
| 110 | name.gsub(/(?u)[^\w\.\-]/, '_') | ||
| 109 | end | 111 | end |
| 110 | 112 | ||
| 111 | # Proxy object returned by asset.upload, providing the Paperclip-compatible | 113 | # Proxy object returned by asset.upload, providing the Paperclip-compatible |
