rmagick-metadata 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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rmagick-metadata.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Rmagick::Metadata
2
+
3
+ Parses an image using RMagick and parses the metadata.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rmagick-metadata'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rmagick-metadata
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ image_path = "/my_rails_app/app/assets/images/rails.png"
23
+
24
+ data = RMagickMetadata.new(image_path)
25
+
26
+ # Helpers
27
+ assert data.filename_suffix == 'png'
28
+ assert data.has_transparency? == true
29
+ assert data.dimensions == [ 50, 64 ]
30
+ assert data.width == 50
31
+ assert data.height == 64
32
+ assert data.file_size == 6646
33
+ assert data.resolution == 72
34
+ assert data.compression_percent == 0.0
35
+
36
+ # Auto-populated
37
+ assert data.file_size_of_image == '6646B'
38
+ assert data.comment == ''
39
+ assert data.directory =~ /\.*\/rmagick-metadata\/test/
40
+ assert data.filename_suffix == 'png'
41
+ assert data.filename_with_suffix == 'rails.png'
42
+ assert data.layer_canvas_page_geometry == '50x64+0+0'
43
+ assert data.current_height_in_pixels == '64'
44
+ assert data.image_filename =~ /\.*\/rmagick-metadata\/test\/rails.png/
45
+ assert data.calculated_number_of_unique_colors == '2018'
46
+ assert data.label == ''
47
+ assert data.image_file_format == 'PNG'
48
+ assert data.number_of_images_in_current_image_sequence == '1'
49
+ assert data.output_filename == ''
50
+ assert data.index_of_image_in_current_image_list == '0'
51
+ assert data.quantum_depth == '16'
52
+ assert data.image_class_and_colorspace == 'DirectClass sRGB Matte'
53
+ assert data.scene_number == '0'
54
+ assert data.filename_without_directory_or_extension == 'rails'
55
+ assert data.unique_temporary_filename == ''
56
+ assert data.current_width_in_pixels == '50'
57
+ assert data.x_resolution_density == '72 Undefined'
58
+ assert data.y_resolution_density == '72 Undefined'
59
+ assert data.image_depth == '8'
60
+ assert data.image_transparency_channel_enabled == 'True'
61
+ assert data.image_compression_type == 'Zip'
62
+ assert data.image_gif_dispose_method == 'Undefined'
63
+ assert data.image_size_w_x_h == '50x64'
64
+ assert data.page_canvas_height == '64'
65
+ assert data.magick_filename =~ /\.*\/rmagick-metadata\/test\/rails.png/
66
+ assert data.page_canvas_offset == '+0+0'
67
+ assert data.page_canvas_size == '50x64'
68
+ assert data.image_compression_quality == '0'
69
+ assert data.scenes == '2147483647'
70
+ assert data.image_time_delay == '0'
71
+ assert data.page_canvas_width == '50'
72
+ assert data.page_canvas_x_offset == '0'
73
+ assert data.page_canvas_y_offset == '0'
74
+ assert data.unique_filename == ''
75
+ assert data.calculated_trim_bounding_box == '50x64+0+0'
76
+ assert data.calculated_signature_hash_of_image_values == 'ae231a37d573c2ef941f3345932183b58cf5c0e6a569839d931b6172cebdbe27'
77
+ ```
78
+
79
+ ## Testing
80
+
81
+ The gem is fully tested using [MicroTest](http://hopsoft.github.com/micro_test/). Use the command `mt` to perform the tests.
82
+
83
+ ## Contributing
84
+
85
+ 1. Fork it
86
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
87
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
88
+ 4. Push to the branch (`git push origin my-new-feature`)
89
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,115 @@
1
+ require "RMagick"
2
+
3
+ class RMagickMetadata
4
+
5
+ def initialize( file_path )
6
+
7
+ # Create attr_accessors for all keys in the data_map
8
+ data_map.each do |k, v|
9
+ create_attr v
10
+ end
11
+
12
+ # Get the data for the image using 'identify'
13
+ format_str = data_map.keys.map{|k|"%#{k}"}.join('|')
14
+ data = %x[identify -format "#{format_str}" #{file_path}].chomp
15
+
16
+ # Parse the data response and assign it to the instance values
17
+ data.split('|').each_with_index do |val, idx|
18
+ attr_name = data_map.values[idx]
19
+ instance_variable_set("@#{attr_name}", val)
20
+ end
21
+
22
+ end
23
+
24
+ # Helper methods
25
+
26
+ def has_transparency?
27
+ @image_transparency_channel_enabled == 'True'
28
+ end
29
+
30
+ def dimensions
31
+ [@current_width_in_pixels.to_i, @current_height_in_pixels.to_i]
32
+ end
33
+
34
+ def file_size
35
+ @file_size_of_image.scan(/\d/).join().to_i if @file_size_of_image
36
+ end
37
+
38
+ def resolution
39
+ @x_resolution_density.scan(/\d/).join().to_i if @x_resolution_density
40
+ end
41
+
42
+ def compression_percent
43
+ @image_compression_quality.to_f if @image_compression_quality
44
+ end
45
+
46
+ def width
47
+ dimensions[0]
48
+ end
49
+
50
+ def height
51
+ dimensions[1]
52
+ end
53
+
54
+ protected
55
+
56
+ def data_map
57
+ {
58
+ 'b' => 'file_size_of_image',
59
+ 'c' => 'comment',
60
+ 'd' => 'directory',
61
+ 'e' => 'filename_suffix',
62
+ 'f' => 'filename_with_suffix',
63
+ 'g' => 'layer_canvas_page_geometry',
64
+ 'h' => 'current_height_in_pixels',
65
+ 'i' => 'image_filename',
66
+ 'k' => 'calculated_number_of_unique_colors',
67
+ 'l' => 'label',
68
+ 'm' => 'image_file_format',
69
+ 'n' => 'number_of_images_in_current_image_sequence',
70
+ 'o' => 'output_filename',
71
+ 'p' => 'index_of_image_in_current_image_list',
72
+ 'q' => 'quantum_depth',
73
+ 'r' => 'image_class_and_colorspace',
74
+ 's' => 'scene_number',
75
+ 't' => 'filename_without_directory_or_extension',
76
+ 'u' => 'unique_temporary_filename',
77
+ 'w' => 'current_width_in_pixels',
78
+ 'x' => 'x_resolution_density',
79
+ 'y' => 'y_resolution_density',
80
+ 'z' => 'image_depth',
81
+ 'A' => 'image_transparency_channel_enabled',
82
+ 'C' => 'image_compression_type',
83
+ 'D' => 'image_gif_dispose_method',
84
+ 'G' => 'image_size_w_x_h',
85
+ 'H' => 'page_canvas_height',
86
+ 'M' => 'magick_filename',
87
+ 'O' => 'page_canvas_offset',
88
+ 'P' => 'page_canvas_size',
89
+ 'Q' => 'image_compression_quality',
90
+ 'S' => 'scenes',
91
+ 'T' => 'image_time_delay',
92
+ 'W' => 'page_canvas_width',
93
+ 'X' => 'page_canvas_x_offset',
94
+ 'Y' => 'page_canvas_y_offset',
95
+ 'Z' => 'unique_filename',
96
+ '@' => 'calculated_trim_bounding_box',
97
+ '#' => 'calculated_signature_hash_of_image_values'
98
+ }
99
+ end
100
+
101
+ def create_method( name, &block )
102
+ self.class.send( :define_method, name, &block )
103
+ end
104
+
105
+ def create_attr( name )
106
+ create_method( "#{name}=".to_sym ) { |val|
107
+ instance_variable_set( "@" + name, val)
108
+ }
109
+
110
+ create_method( name.to_sym ) {
111
+ instance_variable_get( "@" + name )
112
+ }
113
+ end
114
+
115
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "rmagick-metadata"
7
+ gem.version = "0.0.1"
8
+ gem.authors = ["Eric Berry"]
9
+ gem.email = ["cavneb@gmail.com"]
10
+ gem.description = %q{Parses an image using RMagick and parses the metadata}
11
+ gem.summary = %q{Parses an image using RMagick and parses the metadata}
12
+ gem.homepage = "http://github.com/cavneb/rmagick-metadata"
13
+
14
+ gem.add_dependency "rmagick"
15
+ gem.add_development_dependency "micro_test"
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
data/test/rails.png ADDED
Binary file
@@ -0,0 +1,64 @@
1
+ require File.expand_path("../test_helper", __FILE__)
2
+
3
+ class RMagickMetadataTest < MicroTest::Test
4
+
5
+ test "initialize and populate data" do
6
+ image_path = File.expand_path("../rails.png", __FILE__)
7
+ assert File.exist? image_path
8
+
9
+ data = ::RMagickMetadata.new(image_path)
10
+
11
+ # Helpers
12
+ assert data.filename_suffix == 'png'
13
+ assert data.has_transparency? == true
14
+ assert data.dimensions == [ 50, 64 ]
15
+ assert data.width == 50
16
+ assert data.height == 64
17
+ assert data.file_size == 6646
18
+ assert data.resolution == 72
19
+ assert data.compression_percent == 0.0
20
+
21
+ # Auto-populated
22
+ assert data.file_size_of_image == '6646B'
23
+ assert data.comment == ''
24
+ assert data.directory =~ /\.*\/rmagick-metadata\/test/
25
+ assert data.filename_suffix == 'png'
26
+ assert data.filename_with_suffix == 'rails.png'
27
+ assert data.layer_canvas_page_geometry == '50x64+0+0'
28
+ assert data.current_height_in_pixels == '64'
29
+ assert data.image_filename =~ /\.*\/rmagick-metadata\/test\/rails.png/
30
+ assert data.calculated_number_of_unique_colors == '2018'
31
+ assert data.label == ''
32
+ assert data.image_file_format == 'PNG'
33
+ assert data.number_of_images_in_current_image_sequence == '1'
34
+ assert data.output_filename == ''
35
+ assert data.index_of_image_in_current_image_list == '0'
36
+ assert data.quantum_depth == '16'
37
+ assert data.image_class_and_colorspace == 'DirectClass sRGB Matte'
38
+ assert data.scene_number == '0'
39
+ assert data.filename_without_directory_or_extension == 'rails'
40
+ assert data.unique_temporary_filename == ''
41
+ assert data.current_width_in_pixels == '50'
42
+ assert data.x_resolution_density == '72 Undefined'
43
+ assert data.y_resolution_density == '72 Undefined'
44
+ assert data.image_depth == '8'
45
+ assert data.image_transparency_channel_enabled == 'True'
46
+ assert data.image_compression_type == 'Zip'
47
+ assert data.image_gif_dispose_method == 'Undefined'
48
+ assert data.image_size_w_x_h == '50x64'
49
+ assert data.page_canvas_height == '64'
50
+ assert data.magick_filename =~ /\.*\/rmagick-metadata\/test\/rails.png/
51
+ assert data.page_canvas_offset == '+0+0'
52
+ assert data.page_canvas_size == '50x64'
53
+ assert data.image_compression_quality == '0'
54
+ assert data.scenes == '2147483647'
55
+ assert data.image_time_delay == '0'
56
+ assert data.page_canvas_width == '50'
57
+ assert data.page_canvas_x_offset == '0'
58
+ assert data.page_canvas_y_offset == '0'
59
+ assert data.unique_filename == ''
60
+ assert data.calculated_trim_bounding_box == '50x64+0+0'
61
+ assert data.calculated_signature_hash_of_image_values == 'ae231a37d573c2ef941f3345932183b58cf5c0e6a569839d931b6172cebdbe27'
62
+ end
63
+
64
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ Dir[File.dirname(__FILE__) + '/../lib/**/*.rb'].each {|file| require file }
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rmagick-metadata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Berry
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rmagick
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: micro_test
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Parses an image using RMagick and parses the metadata
47
+ email:
48
+ - cavneb@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/rmagick-metadata.rb
59
+ - rmagick-metadata.gemspec
60
+ - test/rails.png
61
+ - test/rmagick_metadata_test.rb
62
+ - test/test_helper.rb
63
+ homepage: http://github.com/cavneb/rmagick-metadata
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Parses an image using RMagick and parses the metadata
87
+ test_files:
88
+ - test/rails.png
89
+ - test/rmagick_metadata_test.rb
90
+ - test/test_helper.rb