summaryrefslogtreecommitdiff
path: root/app/models/concerns
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/file_attachment.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/app/models/concerns/file_attachment.rb b/app/models/concerns/file_attachment.rb
index 5e0803fd..fd0cabed 100644
--- a/app/models/concerns/file_attachment.rb
+++ b/app/models/concerns/file_attachment.rb
@@ -29,6 +29,14 @@ module FileAttachment
29 large: { args: ["-resize", "1600x1600>"] } 29 large: { args: ["-resize", "1600x1600>"] }
30 }.freeze 30 }.freeze
31 31
32 # Prepended to ImageMagick's configuration search path on every
33 # invocation, so config/imagemagick/policy.xml is read before the
34 # installed one. Per-invocation rather than in the environment, so it
35 # cannot leak into anything else on the host.
36 MAGICK_ENV = {
37 "MAGICK_CONFIGURE_PATH" => Rails.root.join("config", "imagemagick").to_s
38 }.freeze
39
32 IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze 40 IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze
33 VECTOR_CONTENT_TYPES = %w[image/svg+xml].freeze 41 VECTOR_CONTENT_TYPES = %w[image/svg+xml].freeze
34 RASTERIZED_CONTENT_TYPES = %w[application/pdf].freeze 42 RASTERIZED_CONTENT_TYPES = %w[application/pdf].freeze
@@ -152,7 +160,7 @@ module FileAttachment
152 STYLES.each do |style, options| 160 STYLES.each do |style, options|
153 dest_path = file_path(style) 161 dest_path = file_path(style)
154 FileUtils.mkdir_p(File.dirname(dest_path)) 162 FileUtils.mkdir_p(File.dirname(dest_path))
155 system("magick", original_path, *extra_args, *options[:args], dest_path) 163 system(MAGICK_ENV, "magick", original_path, *extra_args, *options[:args], dest_path)
156 end 164 end
157 end 165 end
158 166
@@ -173,13 +181,13 @@ module FileAttachment
173 FileUtils.mkdir_p(File.dirname(dest_path)) 181 FileUtils.mkdir_p(File.dirname(dest_path))
174 182
175 if og_full_bleed?(original_path) 183 if og_full_bleed?(original_path)
176 system("magick", "#{original_path}[0]", 184 system(MAGICK_ENV, "magick", "#{original_path}[0]",
177 "-resize", "#{OG_WIDTH}x#{OG_HEIGHT}^", 185 "-resize", "#{OG_WIDTH}x#{OG_HEIGHT}^",
178 "-gravity", "center", "-extent", "#{OG_WIDTH}x#{OG_HEIGHT}", 186 "-gravity", "center", "-extent", "#{OG_WIDTH}x#{OG_HEIGHT}",
179 "-background", OG_GROUND, "-alpha", "remove", "-alpha", "off", 187 "-background", OG_GROUND, "-alpha", "remove", "-alpha", "off",
180 *og_output_args, dest_path) 188 *og_output_args, dest_path)
181 else 189 else
182 system(*og_template_command(dest_path)) 190 system(MAGICK_ENV, *og_template_command(dest_path))
183 end 191 end
184 end 192 end
185 193
@@ -206,7 +214,7 @@ module FileAttachment
206 end 214 end
207 215
208 def source_dimensions(path) 216 def source_dimensions(path)
209 out, status = Open3.capture2("magick", "identify", "-format", "%w %h", "#{path}[0]") 217 out, status = Open3.capture2(MAGICK_ENV, "magick", "identify", "-format", "%w %h", "#{path}[0]")
210 return nil unless status.success? 218 return nil unless status.success?
211 219
212 width, height = out.split.map(&:to_i) 220 width, height = out.split.map(&:to_i)