Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def deletable?
end

def image_file_extension
image_file&.ext&.downcase
read_attribute(:image_file_format)
end
alias_method :suffix, :image_file_extension
deprecate suffix: :image_file_extension, deprecator: Alchemy::Deprecation
Expand Down
6 changes: 3 additions & 3 deletions app/models/alchemy/picture_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ def encoded_image(image, options = {})
end

options = {
flatten: !render_format.in?(ANIMATED_IMAGE_FORMATS) && picture.image_file_format == "gif"
flatten: !render_format.in?(ANIMATED_IMAGE_FORMATS) && picture.image_file_extension == "gif"
}.with_indifferent_access.merge(options)

encoding_options = []

convert_format = render_format.sub("jpeg", "jpg") != picture.image_file_format.sub("jpeg", "jpg")
convert_format = render_format.sub("jpeg", "jpg") != picture.image_file_extension.sub("jpeg", "jpg")

if encodable_image? && (convert_format || options[:quality])
quality = options[:quality] || Alchemy.config.get(:output_image_quality)
encoding_options << "-quality #{quality}"
end

if options[:flatten]
if render_format.in?(TRANSPARENT_IMAGE_FORMATS) && picture.image_file_format.in?(TRANSPARENT_IMAGE_FORMATS)
if render_format.in?(TRANSPARENT_IMAGE_FORMATS) && picture.image_file_extension.in?(TRANSPARENT_IMAGE_FORMATS)
encoding_options << "-background transparent"
end
encoding_options << "-flatten"
Expand Down
10 changes: 5 additions & 5 deletions spec/models/alchemy/picture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ module Alchemy

describe "#convertible?" do
let(:picture) do
Picture.new(image_file_format: "image/png")
Picture.new(image_file_format: "png")
end

subject { picture.convertible? }
Expand All @@ -473,16 +473,16 @@ module Alchemy
end

context "and the image has a convertible format" do
before do
expect(picture).to receive(:has_convertible_format?) { true }
let(:picture) do
Picture.new(image_file_format: "png")
end

it { is_expected.to be(true) }
end

context "but the image has no convertible format" do
before do
expect(picture).to receive(:has_convertible_format?) { false }
let(:picture) do
Picture.new(image_file_format: "svg")
end

it { is_expected.to be(false) }
Expand Down