Skip to content

Commit

Permalink
cropでエラーにならないように小数点を設定する
Browse files Browse the repository at this point in the history
  • Loading branch information
yocchan-git committed Mar 9, 2024
1 parent 953798d commit 7b004a7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -828,14 +828,14 @@ def calculate_avatar_size_fit_and_crop(width, height, long_side)
avatar_size = {}
case long_side
when :width
resized_width = 120 * width / height
avatar_size[:fit] = [resized_width.floor, 120]
resized_width = (120 * width.to_f / height).ceil
avatar_size[:fit] = [resized_width, 120]

cut_out_start_point = (resized_width - 120) / 2
avatar_size[:crop] = [cut_out_start_point.floor, 0]
when :height
resized_height = 120 * height / width
avatar_size[:fit] = [120, resized_height.floor]
resized_height = (120 * height.to_f / width).ceil
avatar_size[:fit] = [120, resized_height]

cut_out_start_point = (resized_height - 120) / 2
avatar_size[:crop] = [0, cut_out_start_point.floor]
Expand Down

0 comments on commit 7b004a7

Please sign in to comment.