Skip to content

Commit

Permalink
Do not convert JPG images into JPEG (#1905)
Browse files Browse the repository at this point in the history
As JPG and JPEG are technically the same image we must not convert them.
  • Loading branch information
tvdeyen authored Jul 26, 2020
1 parent 4e512db commit f9b70e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/alchemy/picture_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def encoded_image(image, options = {})

encoding_options = []

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

if render_format =~ /jpe?g/ && convert_format
quality = options[:quality] || Config.get(:output_image_jpg_quality)
Expand Down
28 changes: 28 additions & 0 deletions spec/models/alchemy/picture_variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,32 @@
end
end
end

context "when jpeg format is requested" do
let(:options) do
{
format: "jpeg",
}
end

context "and image has jpg format" do
let(:alchemy_picture) do
build_stubbed(:alchemy_picture, image_file: image_file, image_file_format: "jpg")
end

it "does not convert the picture format" do
expect(subject).to_not respond_to(:steps)
end
end

context "and image has jpeg format" do
let(:alchemy_picture) do
build_stubbed(:alchemy_picture, image_file: image_file, image_file_format: "jpeg")
end

it "does not convert the picture format" do
expect(subject).to_not respond_to(:steps)
end
end
end
end

0 comments on commit f9b70e0

Please sign in to comment.