2026-03-06 10:56:20 -05:00
|
|
|
module IdCard
|
|
|
|
|
class NetworkLogo < ApplicationRecord
|
2026-04-15 08:12:47 -04:00
|
|
|
# before_validation :resize_logo, if: :image_data_changed?
|
|
|
|
|
# before_validation :calculate_aspect_ratio, if: :image_data_changed?
|
|
|
|
|
before_validation :process_image, if: :image_data_changed?
|
2026-03-13 08:47:13 -04:00
|
|
|
|
|
|
|
|
scope :defaults, -> { where(default: true) }
|
|
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
|
|
def medcost
|
2026-03-19 00:42:27 -04:00
|
|
|
defaults.where("filename LIKE ?", "%MedCost%")
|
2026-03-13 08:47:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cigna
|
|
|
|
|
defaults.where("filename LIKE ?", "%Cigna%")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
2026-03-03 22:53:21 -05:00
|
|
|
|
2026-03-06 10:56:20 -05:00
|
|
|
private
|
2026-03-03 22:53:21 -05:00
|
|
|
|
2026-04-15 08:12:47 -04:00
|
|
|
def process_image
|
|
|
|
|
image = Vips::Image.new_from_buffer(self.image_data, "")
|
|
|
|
|
|
|
|
|
|
resized_image = ImageProcessing::Vips
|
|
|
|
|
.source(image)
|
|
|
|
|
.resize_to_limit(nil, 400)
|
|
|
|
|
|
|
|
|
|
processed_image = resized_image.convert("png").call
|
|
|
|
|
new_image_data = processed_image.read
|
|
|
|
|
if new_image_data
|
|
|
|
|
self.image_data = new_image_data
|
|
|
|
|
self.filename = File.basename(self.filename, File.extname(self.filename)) + ".png"
|
|
|
|
|
self.content_type = "image/png"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
image_ratio = image.width.to_f / image.height
|
2026-03-13 08:47:13 -04:00
|
|
|
if image_ratio
|
|
|
|
|
self.aspect_ratio = image_ratio.round(2)
|
2026-03-06 10:56:20 -05:00
|
|
|
end
|
2026-03-03 22:53:21 -05:00
|
|
|
end
|
2026-03-13 08:47:13 -04:00
|
|
|
|
2026-04-15 08:12:47 -04:00
|
|
|
# def resize_logo
|
|
|
|
|
# image = Vips::Image.new_from_buffer(self.image_data, "")
|
|
|
|
|
|
|
|
|
|
# processed_image = ImageProcessing::Vips
|
|
|
|
|
# .source(image)
|
|
|
|
|
# .resize_to_limit(nil, 400)
|
|
|
|
|
# .call
|
|
|
|
|
|
|
|
|
|
# self.image_data = processed_image.read
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# def calculate_aspect_ratio
|
|
|
|
|
# image_io = StringIO.new(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
|
|
|
|
|
|
2026-03-03 22:53:21 -05:00
|
|
|
end
|
2025-12-10 13:22:33 -05:00
|
|
|
end
|