Files
Notare/lib/notare/nodes/image.rb
mathias234 dec346254c
All checks were successful
CI Pipeline / build (push) Successful in 12s
Project rename
2025-12-02 13:21:13 +01:00

39 lines
907 B
Ruby

# frozen_string_literal: true
module Notare
module Nodes
class Image < Base
attr_reader :path, :width_emu, :height_emu, :rid, :filename
EMUS_PER_INCH = 914_400
EMUS_PER_CM = 360_000
DEFAULT_DPI = 96
def initialize(path, rid:, width_emu:, height_emu:)
super()
@path = path
@rid = rid
@width_emu = width_emu
@height_emu = height_emu
@filename = "image#{rid.delete_prefix("rId")}.#{extension}"
end
def extension
case File.extname(@path).downcase
when ".png" then "png"
when ".jpg", ".jpeg" then "jpeg"
else raise ArgumentError, "Unsupported image format: #{File.extname(@path)}"
end
end
def content_type
extension == "png" ? "image/png" : "image/jpeg"
end
def doc_pr_id
rid.delete_prefix("rId").to_i
end
end
end
end