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

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/pdf-writer-1.1.8/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)
JPEG_APP_BLOCKS =
%W(\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef)
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



54
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
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb', line 54

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.



97
98
99
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb', line 97

def bits
  @bits
end

#channelsObject (readonly)

Returns the value of attribute channels.



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

def channels
  @channels
end

#formatObject (readonly) Also known as: get_type

Returns the value of attribute format.



90
91
92
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb', line 90

def format
  @format
end

#heightObject (readonly) Also known as: get_height

Returns the value of attribute height.



92
93
94
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb', line 92

def height
  @height
end

#infoObject (readonly)

Returns the value of attribute info.



100
101
102
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb', line 100

def info
  @info
end

#widthObject (readonly) Also known as: get_width

Returns the value of attribute width.



94
95
96
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb', line 94

def width
  @width
end

Class Method Details

.formatsObject Also known as: type_list



44
45
46
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb', line 44

def formats
  Formats.constants
end