class HexaPDF::CLI::Images::ImageLocationProcessor
Extracts the PPI (pixel per inch) information for each image of a content stream.
Attributes
result[R]
The mapping of XObject name to [x_ppi, y_ppi].
Public Class Methods
new(names, user_unit)
click to toggle source
Initialize the processor with the names of the images for which the PPI should be determined.
Calls superclass method
HexaPDF::Content::Processor::new
# File lib/hexapdf/cli/images.rb, line 55 def initialize(names, user_unit) super() @names = names @user_unit = user_unit @result = {} end
Public Instance Methods
paint_xobject(name)
click to toggle source
Determine the PPI in x- and y-directions of the specified images.
Calls superclass method
HexaPDF::Content::Processor#paint_xobject
# File lib/hexapdf/cli/images.rb, line 63 def paint_xobject(name) super return unless @names.delete(name) xobject = resources.xobject(name) return unless xobject[:Subtype] == :Image w, h = xobject.width, xobject.height llx, lly = graphics_state.ctm.evaluate(0, 0).map {|i| i * @user_unit } lrx, lry = graphics_state.ctm.evaluate(1, 0).map {|i| i * @user_unit } ulx, uly = graphics_state.ctm.evaluate(0, 1).map {|i| i * @user_unit } x_ppi = 72.0 * w / Math.sqrt((lrx - llx)**2 + (lry - lly)**2) y_ppi = 72.0 * h / Math.sqrt((ulx - llx)**2 + (uly - lly)**2) @result[name] = [x_ppi.round, y_ppi.round] raise StopIteration if @names.empty? end