Class ImageSize
In: lib/image_size.rb
Parent: Object

Methods

get_height   get_size   get_type   get_width   h   height   new   size   type_list   w   width  

Classes and Modules

Module ImageSize::Type

Constants

JpegCodeCheck = [ "\xc0", "\xc1", "\xc2", "\xc3", "\xc5", "\xc6", "\xc7", "\xc9", "\xca", "\xcb", "\xcd", "\xce", "\xcf", ]

Public Class methods

receive image & make size argument 1 is image String, StringIO or IO argument 2 is type(ImageSize::Type::GIF and so on.) or nil

[Source]

    # File lib/image_size.rb, line 40
40:   def initialize(img_data, img_type = nil)
41:     @img_data = img_data.dup
42:     @img_width  = nil
43:     @img_height = nil
44:     @img_type   = nil
45: 
46:     if @img_data.is_a?(IO)
47:       img_top = @img_data.read(1024)
48:       img_io = def_read_o(@img_data)
49:     elsif @img_data.is_a?(StringIO)
50:       img_top = @img_data.read(1024)
51:       img_io = def_read_o(@img_data)
52:     elsif @img_data.is_a?(String)
53:       img_top = @img_data[0, 1024]
54: #      img_io = StringIO.open(@img_data){|sio| io = def_read_o(sio); io }

55:       img_io = StringIO.open(@img_data)
56:       img_io = def_read_o(img_io)
57:     else
58:       raise "argument class error!! #{img_data.type}"
59:     end
60:     
61:     if @img_type.nil?
62:       @img_type = check_type(img_top)
63:     else
64:       type = Type.constants.find{|t| img_type == t }
65:       raise("type is failed. #{img_type}\n") if !type
66:       @img_type = img_type
67:     end
68: 
69:     if @img_type != Type::OTHER
70:       @img_width, @img_height = self.__send__("measure_#{@img_type}", img_io)
71:     else
72:       @img_width, @img_height = [nil, nil]
73:     end
74:     
75:     if @img_data.is_a?(String)
76:       img_io.close
77:     end
78:   end

image type list

[Source]

    # File lib/image_size.rb, line 33
33:   def ImageSize.type_list
34:     Type.constants 
35:   end

Public Instance methods

get image height

[Source]

    # File lib/image_size.rb, line 85
85:   def get_height
86:     if @img_type == Type::OTHER then nil else @img_height end
87:   end

get image width and height(Array)

[Source]

    # File lib/image_size.rb, line 95
95:   def get_size
96:     [self.get_width, self.get_height]
97:   end

get image type ex. "GIF", "PNG", "JPEG"

[Source]

    # File lib/image_size.rb, line 82
82:   def get_type; @img_type; end

get image width

[Source]

    # File lib/image_size.rb, line 90
90:   def get_width
91:     if @img_type == Type::OTHER then nil else @img_width end
92:   end
h()

Alias for get_height

height()

Alias for get_height

size()

Alias for get_size

w()

Alias for get_width

width()

Alias for get_width

[Validate]