Major features finished

This commit is contained in:
Jason Jordan
2026-04-15 08:12:47 -04:00
parent 9f306d3150
commit 247a075c9c
112 changed files with 3700 additions and 379 deletions
+39 -5
View File
@@ -1,6 +1,8 @@
module IdCard
class NetworkLogo < ApplicationRecord
before_validation :calculate_aspect_ratio, if: :image_data_changed?
# 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?
scope :defaults, -> { where(default: true) }
@@ -18,14 +20,46 @@ module IdCard
private
def calculate_aspect_ratio
image_io = StringIO.new(image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
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
if image_ratio
self.aspect_ratio = image_ratio.round(2)
end
end
# 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
end
end