15 lines
364 B
Ruby
15 lines
364 B
Ruby
|
|
class IdCard::EmployerLogo < ApplicationRecord
|
||
|
|
before_save :calculate_aspect_ratio, if: :image_data_changed?
|
||
|
|
|
||
|
|
private
|
||
|
|
|
||
|
|
def calculate_aspect_ratio
|
||
|
|
image_io = StringIO.new(self.image_data)
|
||
|
|
width, height = FastImage.size(image_io)
|
||
|
|
image_ratio = width.to_f / height
|
||
|
|
if image_ratio
|
||
|
|
self.aspect_ratio = image_ratio.round(2)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|