Rubimage 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/lib/rubimage/image_reader.rb +46 -0
 - data/lib/rubimage/jpg_reader.rb +25 -0
 - data/lib/rubimage/png_reader.rb +21 -0
 - data/lib/rubimage.rb +23 -0
 - metadata +46 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 0e9c789c6c8f0917ed10803ace15083da17ddb23
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1b2af86c3bf23f5b3e466b4443b78580535c84f9
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 52b541af0fa5a54c446f1e23203be3fa009d75926adac51bd48af56807c172c8596403b499e6ed33574f33db51a3c6c03963220937f81a879bd7a5bbdfe16b73
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b71b7d5c8ef6fd2f89aec393059019c1962dfb2bc4b5447726793b42761a4f3938faa29dac7539dcf69f1570c18f715b52f5abf55bf8aca8a5c84b2aceaec21d
         
     | 
| 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Rubimage
         
     | 
| 
      
 2 
     | 
    
         
            +
              class ImageReader
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                BINARY     = 'rb'
         
     | 
| 
      
 5 
     | 
    
         
            +
                BYTE       = 1
         
     | 
| 
      
 6 
     | 
    
         
            +
                TWO_BYTES  = 2
         
     | 
| 
      
 7 
     | 
    
         
            +
                FOUR_BYTES = 4
         
     | 
| 
      
 8 
     | 
    
         
            +
                SHORT      = 'n'
         
     | 
| 
      
 9 
     | 
    
         
            +
                INT        = 'N'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                attr_reader :width, :height, :dimensions
         
     | 
| 
      
 12 
     | 
    
         
            +
                
         
     | 
| 
      
 13 
     | 
    
         
            +
                def initialize(path)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @file = File.open path, BINARY
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                private 
         
     | 
| 
      
 18 
     | 
    
         
            +
                  def end?
         
     | 
| 
      
 19 
     | 
    
         
            +
                    @file.eof?
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  def skip_bytes(bytes = 1)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @file.read BYTE * bytes
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  def next_byte
         
     | 
| 
      
 27 
     | 
    
         
            +
                    @file.readbyte
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  def next_short
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @file.read(TWO_BYTES).unpack(SHORT)[0]
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  def next_int
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @file.read(FOUR_BYTES).unpack(INT)[0]
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  def closed?
         
     | 
| 
      
 39 
     | 
    
         
            +
                    @file.closed?
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  def close
         
     | 
| 
      
 43 
     | 
    
         
            +
                    @file.close
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Rubimage
         
     | 
| 
      
 2 
     | 
    
         
            +
            	class JpgReader < ImageReader
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            		FF  = 0xff
         
     | 
| 
      
 5 
     | 
    
         
            +
            		SOf = 0xc0..0xcf
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            		def initialize(path)
         
     | 
| 
      
 8 
     | 
    
         
            +
            			super path
         
     | 
| 
      
 9 
     | 
    
         
            +
            			read
         
     | 
| 
      
 10 
     | 
    
         
            +
            		end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            		def read
         
     | 
| 
      
 13 
     | 
    
         
            +
            			until closed? or end?
         
     | 
| 
      
 14 
     | 
    
         
            +
            				buf = next_byte
         
     | 
| 
      
 15 
     | 
    
         
            +
            				if buf == FF and SOf.include? next_byte
         
     | 
| 
      
 16 
     | 
    
         
            +
            					skip_bytes 3
         
     | 
| 
      
 17 
     | 
    
         
            +
            					@height = next_short
         
     | 
| 
      
 18 
     | 
    
         
            +
            					@width  = next_short
         
     | 
| 
      
 19 
     | 
    
         
            +
            					@dimensions = [@width, @height]
         
     | 
| 
      
 20 
     | 
    
         
            +
            					close
         
     | 
| 
      
 21 
     | 
    
         
            +
            				end
         
     | 
| 
      
 22 
     | 
    
         
            +
            			end
         
     | 
| 
      
 23 
     | 
    
         
            +
            		end
         
     | 
| 
      
 24 
     | 
    
         
            +
            	end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Rubimage
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              class PngReader < ImageReader
         
     | 
| 
      
 4 
     | 
    
         
            +
                PNG_HEADER = 16
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def initialize(path)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  super(path)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  read
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                private 
         
     | 
| 
      
 12 
     | 
    
         
            +
                  def read
         
     | 
| 
      
 13 
     | 
    
         
            +
                    skip_bytes PNG_HEADER
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @width  = next_int
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @height = next_int
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @dimensions = [@width, @height]
         
     | 
| 
      
 17 
     | 
    
         
            +
                    close
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/rubimage.rb
    ADDED
    
    | 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'rubimage/image_reader'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'rubimage/jpg_reader'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'rubimage/png_reader'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module Rubimage
         
     | 
| 
      
 6 
     | 
    
         
            +
            	
         
     | 
| 
      
 7 
     | 
    
         
            +
            	PNG  = '.png'
         
     | 
| 
      
 8 
     | 
    
         
            +
              JPG  = '.jpg'
         
     | 
| 
      
 9 
     | 
    
         
            +
              JPEG = '.jpeg'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            	def self.Info(path)
         
     | 
| 
      
 12 
     | 
    
         
            +
            		ext_type = File.extname path
         
     | 
| 
      
 13 
     | 
    
         
            +
            		case ext_type
         
     | 
| 
      
 14 
     | 
    
         
            +
            		when PNG
         
     | 
| 
      
 15 
     | 
    
         
            +
            			type = Rubimage::PngReader.new path
         
     | 
| 
      
 16 
     | 
    
         
            +
            		when JPG, JPEG
         
     | 
| 
      
 17 
     | 
    
         
            +
            			type = Rubimage::JpgReader.new path
         
     | 
| 
      
 18 
     | 
    
         
            +
            		else
         
     | 
| 
      
 19 
     | 
    
         
            +
            			raise "#{ext_type} is not currently supported"
         
     | 
| 
      
 20 
     | 
    
         
            +
            		end	
         
     | 
| 
      
 21 
     | 
    
         
            +
            	end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: Rubimage
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Dylan
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-06-18 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: Rubimage gives you the width and height of an jpg, png and tiff
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: 
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 16 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            files:
         
     | 
| 
      
 19 
     | 
    
         
            +
            - lib/rubimage.rb
         
     | 
| 
      
 20 
     | 
    
         
            +
            - lib/rubimage/image_reader.rb
         
     | 
| 
      
 21 
     | 
    
         
            +
            - lib/rubimage/jpg_reader.rb
         
     | 
| 
      
 22 
     | 
    
         
            +
            - lib/rubimage/png_reader.rb
         
     | 
| 
      
 23 
     | 
    
         
            +
            homepage: 
         
     | 
| 
      
 24 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 25 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 26 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 27 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 28 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 29 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 30 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 31 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 32 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 33 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 34 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 35 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 36 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 37 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 38 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 39 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 40 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 41 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 42 
     | 
    
         
            +
            rubygems_version: 2.1.10
         
     | 
| 
      
 43 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 44 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 45 
     | 
    
         
            +
            summary: Ruby image tools
         
     | 
| 
      
 46 
     | 
    
         
            +
            test_files: []
         
     |