Skip to content

Commit

Permalink
wip: always return image format
Browse files Browse the repository at this point in the history
Before we where not telling active storage that we want
a certain format explicitely.
We need that for displaying animated PNGs properly.
  • Loading branch information
tvdeyen committed Jan 22, 2024
1 parent f3b374e commit fe22999
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
15 changes: 11 additions & 4 deletions app/models/alchemy/picture/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,36 @@ def initialize(picture)
#
def call(options = {})
variant_options = DragonflyToImageProcessing.call(options)
variant_options[:format] = options[:format] || default_output_format
variant = image_file&.variant(variant_options)
return unless variant

Rails.application.routes.url_helpers.rails_storage_proxy_url(
variant,
{
filename: filename(options),
only_path: true,
format: nil
only_path: true
}
)
end

private

def filename(options = {})
format = options[:format] || picture.image_file_extension
if picture.name.presence
"#{picture.name.to_param}.#{format}"
picture.name.to_param
else
picture.image_file_name
end
end

def default_output_format
if Alchemy::Config.get(:image_output_format) == "original"
picture.image_file_extension
else
Alchemy::Config.get(:image_output_format)
end
end
end
end
end
14 changes: 0 additions & 14 deletions app/services/alchemy/dragonfly_to_image_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module DragonflyToImageProcessing
class << self
def call(options = {})
opts = crop_options(options).presence || resize_options(options)
opts.merge!(format_options(options))
opts.merge!(flatten_options(options))
opts.merge!(quality_options(options))
opts
Expand Down Expand Up @@ -50,13 +49,6 @@ def quality_options(options)
{saver: {quality: quality}}
end

def format_options(options)
format = options[:format] || default_output_format
return {} if format.nil?

{format: format}
end

def flatten_options(options)
case options[:flatten]
when true
Expand Down Expand Up @@ -118,12 +110,6 @@ def sharpen_value(options)
options.key?(:sharpen) ? options[:sharpen] : Alchemy::Config.get(:sharpen_images)
end

def default_output_format
return nil if Alchemy::Config.get(:image_output_format) == "original"

Alchemy::Config.get(:image_output_format)
end

def variant_processor
Rails.application.config.active_storage.variant_processor
end
Expand Down

0 comments on commit fe22999

Please sign in to comment.