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 39 def initialize(img_data, img_type = nil) @img_data = img_data.dup @img_width = nil @img_height = nil @img_type = nil if @img_data.is_a?(IO) img_top = @img_data.read(1024) img_io = def_read_o(@img_data) elsif @img_data.is_a?(StringIO) img_top = @img_data.read(1024) img_io = def_read_o(@img_data) elsif @img_data.is_a?(String) img_top = @img_data[0, 1024] # img_io = StringIO.open(@img_data){|sio| io = def_read_o(sio); io } img_io = StringIO.open(@img_data) img_io = def_read_o(img_io) else raise "argument class error!! #{img_data.type}" end if @img_type.nil? @img_type = check_type(img_top) else type = Type.constants.find{|t| img_type == t } raise("type is failed. #{img_type}\n") if !type @img_type = img_type end if @img_type != Type::OTHER @img_width, @img_height = self.__send__("measure_#{@img_type}", img_io) else @img_width, @img_height = [nil, nil] end if @img_data.is_a?(String) img_io.close end end
image type list
# File lib/image_size.rb, line 32 def ImageSize.type_list Type.constants end
get image height
# File lib/image_size.rb, line 84 def get_height if @img_type == Type::OTHER then nil else @img_height end end
get image width and height(Array)
# File lib/image_size.rb, line 94 def get_size [self.get_width, self.get_height] end
get image type ex. "GIF", "PNG", "JPEG"
# File lib/image_size.rb, line 81 def get_type; @img_type; end
get image width
# File lib/image_size.rb, line 89 def get_width if @img_type == Type::OTHER then nil else @img_width end end