Files
Notare/lib/ezdoc/nodes/image.rb
2025-12-02 11:43:25 +01:00

39 lines
906 B
Ruby

# frozen_string_literal: true
module Ezdoc
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