2026-03-06 10:56:20 -05:00
|
|
|
module IdCard
|
|
|
|
|
class EmployerLogo < ApplicationRecord
|
|
|
|
|
before_save :calculate_aspect_ratio, if: :image_data_changed?
|
2026-03-05 11:30:24 -05:00
|
|
|
|
2026-03-06 10:56:20 -05:00
|
|
|
private
|
2026-03-05 11:30:24 -05:00
|
|
|
|
2026-03-06 10:56:20 -05:00
|
|
|
def calculate_aspect_ratio
|
2026-03-13 08:47:13 -04:00
|
|
|
image_io = StringIO.new(image_data)
|
2026-03-06 10:56:20 -05:00
|
|
|
width, height = FastImage.size(image_io)
|
|
|
|
|
image_ratio = width.to_f / height
|
|
|
|
|
if image_ratio
|
2026-03-13 08:47:13 -04:00
|
|
|
aspect_ratio = image_ratio.round(2)
|
2026-03-06 10:56:20 -05:00
|
|
|
end
|
2026-03-05 11:30:24 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|