Class: PDF::Writer::Graphics::ImageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/writer/graphics/imageinfo.rb

Overview

This is based on ImageSize, by Keisuke Minami <[email protected]>. It can be found at www.rubycgi.org/tools/index.en.htm

This has been integrated into PDF::Writer because as yet there has been no response to emails asking for my extensions to be integrated and a RubyGem package to be made available.

Defined Under Namespace

Modules: Formats

Constant Summary collapse

Type =

Flash

Formats
JPEG_SOF_BLOCKS =
%W(\xc0 \xc1 \xc2 \xc3 \xc5 \xc6 \xc7 \xc9 \xca \xcb \xcd \xce \xcf).collect{|m| m.b}
JPEG_APP_BLOCKS =
%W(\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef).collect{|m| m.b}
XBM_DIMENSIONS_RE =
%r{^\#define\s*\S*\s*(\d+)\s*\n\#define\s*\S*\s*(\d+)}mi
XPM_DIMENSIONS_RE =
%r<"\s*(\d+)\s+(\d+)(\s+\d+\s+\d+){1,2}\s*">m

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, format = nil) ⇒ ImageInfo

Receive image & make size. argument is image String or IO



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 55

def initialize(data, format = nil)
  @data   = data.dup rescue data
  @info   = {}

  if @data.kind_of?(IO)
    @top = @data.read(128)
    @data.seek(0, 0)
      # Define Singleton-method definition to IO (byte, offset)
    def @data.read_o(length = 1, offset = nil)
      self.seek(offset, 0) if offset
      ret = self.read(length)
      raise "cannot read!!" unless ret
      ret
    end
  elsif @data.is_a?(String)
    @top = @data[0, 128]
      # Define Singleton-method definition to String (byte, offset)
    @data.extend(PDF::Writer::OffsetReader)
  else
    raise "argument class error!! #{data.type}"
  end

  if format.nil?
    @format = discover_format
  else
    match = false
    Formats.constants.each { |t| match = true if format == t }
    raise("format is failed. #{format}\n") unless match
    @format = format
  end

  __send__("measure_#@format".intern) unless @format == Formats::OTHER

  @data = data.dup
end

Instance Attribute Details

#bitsObject (readonly)

Returns the value of attribute bits.



98
99
100
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 98

def bits
  @bits
end

#channelsObject (readonly)

Returns the value of attribute channels.



99
100
101
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 99

def channels
  @channels
end

#formatObject (readonly) Also known as: get_type

Returns the value of attribute format.



91
92
93
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 91

def format
  @format
end

#heightObject (readonly) Also known as: get_height

Returns the value of attribute height.



93
94
95
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 93

def height
  @height
end

#infoObject (readonly)

Returns the value of attribute info.



101
102
103
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 101

def info
  @info
end

#widthObject (readonly) Also known as: get_width

Returns the value of attribute width.



95
96
97
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 95

def width
  @width
end

Class Method Details

.formatsObject Also known as: type_list



45
46
47
# File 'lib/pdf/writer/graphics/imageinfo.rb', line 45

def formats
  Formats.constants
end