From c7ed30918154d801c44f77645ead38d4759d2778 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Tue, 14 Jul 2026 15:25:11 +0200 Subject: 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. --- app/models/concerns/file_attachment.rb | 10 +++++----- 1 file 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 extend ActiveSupport::Concern STYLES = { - medium: { geometry: "300x300>", format: nil }, - thumb: { geometry: "100x100>", format: nil }, - headline: { geometry: "460x250!", format: nil }, - large: { geometry: "1600x1600>", format: nil } + medium: { args: ["-resize", "300x300>"] }, + thumb: { args: ["-resize", "100x100>"] }, + headline: { args: ["-resize", "460x250^", "-gravity", "center", "-extent", "460x250"] }, + large: { args: ["-resize", "1600x1600>"] } }.freeze IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze @@ -81,7 +81,7 @@ module FileAttachment STYLES.each do |style, options| dest_path = file_path(style) FileUtils.mkdir_p(File.dirname(dest_path)) - system("magick", original_path, "-resize", options[:geometry], dest_path) + system("magick", original_path, *options[:args], dest_path) end end -- cgit v1.3