class ImgToPdf::Image
Attributes
path[R]
Public Class Methods
from_path(path)
click to toggle source
@param [Pathname] path path to instantiate. @return [ImgToPdf::Image] instance.
# File lib/img_to_pdf/image.rb, line 14 def from_path(path) return new(path) end
new(path)
click to toggle source
# File lib/img_to_pdf/image.rb, line 19 def initialize(path) @dimension_px = nil @path = path end
Public Instance Methods
crop(x, y, width, height) { |sub_image| ... }
click to toggle source
@param [Numeric] x @param [Numeric] y @param [Numeric] width @param [Numeric] height @yieldparam [ImgToPdf::Image] sub_image cropped sub image.
# File lib/img_to_pdf/image.rb, line 39 def crop(x, y, width, height) Tempfile.create(["img_to_pdf-image-", path.extname]) do |f| f.close sub_raw_image_path = Pathname(f.path) raw_image = MiniMagick::Image.open(path) raw_image.crop("#{width}x#{height}+#{x}+#{y}") raw_image.write(sub_raw_image_path) sub_image = self.class.from_path(sub_raw_image_path) yield(sub_image) end end
dimension_px()
click to toggle source
@return [ImgToPdf::Dimension] image dimension. pixels.
# File lib/img_to_pdf/image.rb, line 25 def dimension_px return @dimension_px if @dimension_px image_klass = Prawn::Images.const_get(path.extname.upcase.sub(/\A\./, "")) image = image_klass.new(path.read) @dimension_px = ImgToPdf::Dimension.new(width: image.width, height: image.height) return @dimension_px end