Skip to content

Commit

Permalink
Merge pull request #2580 from AlchemyCMS/backport/7.0-stable/pr-2556
Browse files Browse the repository at this point in the history
[7.0-stable] Merge pull request #2556 from mamhoff/fix-nan-ratio-error
  • Loading branch information
tvdeyen authored Sep 18, 2023
2 parents 7d396cd + c840f53 commit d1b6584
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/concerns/alchemy/picture_thumbnails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def default_crop_size
return nil unless settings[:crop] && settings[:size]

mask = inferred_dimensions_from_string(settings[:size])
return if mask.nil?

zoom = thumbnail_zoom_factor(mask)
return nil if zoom.zero?

Expand Down Expand Up @@ -150,6 +152,8 @@ def inferred_dimensions_from_string(string)
width, height = dimensions_from_string(string)
ratio = image_file_width.to_f / image_file_height.to_i

return if ratio.nan?

if width.zero? && ratio.is_a?(Float)
width = height * ratio
end
Expand Down
20 changes: 20 additions & 0 deletions lib/alchemy/test_support/having_picture_thumbnails_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,26 @@
size: "160x120"
)
end

context "with settings indicating free height" do
let(:settings) do
{
crop: true,
size: "800x"
}
end

it "returns default thumbnail options" do
is_expected.to eq(
crop: true,
crop_from: nil,
crop_size: nil,
flatten: true,
format: "jpg",
size: "160x120"
)
end
end
end
end

Expand Down

0 comments on commit d1b6584

Please sign in to comment.