Class | ImageSize |
In: |
lib/image_size.rb
|
Parent: | Object |
JpegCodeCheck | = | [ "\xc0", "\xc1", "\xc2", "\xc3", "\xc5", "\xc6", "\xc7", "\xc9", "\xca", "\xcb", "\xcd", "\xce", "\xcf", ] |
receive image & make size argument 1 is image String, StringIO or IO argument 2 is type(ImageSize::Type::GIF and so on.) or nil
# 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
# File lib/image_size.rb, line 33 33: def ImageSize.type_list 34: Type.constants 35: end
get image type ex. "GIF", "PNG", "JPEG"
# File lib/image_size.rb, line 82 82: def get_type; @img_type; end