summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-14 15:25:11 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-14 15:25:11 +0200
commitc7ed30918154d801c44f77645ead38d4759d2778 (patch)
tree93cd57c8dd9b76bb1457245deb67685b2b181cc6 /app
parent810cddcb122462d62b31b03295e001ea5f0252ba (diff)
Crop headline images to aspect ratio instead of distorting them
STYLES restructured from a single geometry: string per style to a full args: array, since this fix needs -gravity and -extent alongside -resize, which one geometry string can't express.
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/file_attachment.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/app/models/concerns/file_attachment.rb b/app/models/concerns/file_attachment.rb
index 86e5c68..613a6f0 100644
--- a/app/models/concerns/file_attachment.rb
+++ b/app/models/concerns/file_attachment.rb
@@ -23,10 +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: { geometry: "1600x1600>", format: nil } 29 large: { args: ["-resize", "1600x1600>"] }
30 }.freeze 30 }.freeze
31 31
32 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
@@ -81,7 +81,7 @@ module FileAttachment
81 STYLES.each do |style, options| 81 STYLES.each do |style, options|
82 dest_path = file_path(style) 82 dest_path = file_path(style)
83 FileUtils.mkdir_p(File.dirname(dest_path)) 83 FileUtils.mkdir_p(File.dirname(dest_path))
84 system("magick", original_path, "-resize", options[:geometry], dest_path) 84 system("magick", original_path, *options[:args], dest_path)
85 end 85 end
86 end 86 end
87 87