magick-metadata 0.0.3
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 +18 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +91 -0
- data/Rakefile +1 -0
- data/lib/magick-metadata.rb +113 -0
- data/magick-metadata.gemspec +20 -0
- data/test/magick_metadata_test.rb +64 -0
- data/test/rails.png +0 -0
- data/test/test_helper.rb +4 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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,91 @@
|
|
1
|
+
# Magick::Metadata
|
2
|
+
|
3
|
+
Parses an image using ImageMagick and parses the metadata.
|
4
|
+
|
5
|
+
For this gem to work, [ImageMagick](http://www.imagemagick.org/script/index.php) must be installed.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'magick-metadata'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install magick-metadata
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
image_path = "/my_rails_app/app/assets/images/rails.png"
|
25
|
+
|
26
|
+
data = MagickMetadata.new(image_path)
|
27
|
+
|
28
|
+
# Helpers
|
29
|
+
assert data.filename_suffix == 'png'
|
30
|
+
assert data.has_transparency? == true
|
31
|
+
assert data.dimensions == [ 50, 64 ]
|
32
|
+
assert data.width == 50
|
33
|
+
assert data.height == 64
|
34
|
+
assert data.file_size == 6646
|
35
|
+
assert data.resolution == 72
|
36
|
+
assert data.compression_percent == 0.0
|
37
|
+
|
38
|
+
# Auto-populated
|
39
|
+
assert data.file_size_of_image == '6646B'
|
40
|
+
assert data.comment == ''
|
41
|
+
assert data.directory =~ /\.*\/magick-metadata\/test/
|
42
|
+
assert data.filename_suffix == 'png'
|
43
|
+
assert data.filename_with_suffix == 'rails.png'
|
44
|
+
assert data.layer_canvas_page_geometry == '50x64+0+0'
|
45
|
+
assert data.current_height_in_pixels == '64'
|
46
|
+
assert data.image_filename =~ /\.*\/magick-metadata\/test\/rails.png/
|
47
|
+
assert data.calculated_number_of_unique_colors == '2018'
|
48
|
+
assert data.label == ''
|
49
|
+
assert data.image_file_format == 'PNG'
|
50
|
+
assert data.number_of_images_in_current_image_sequence == '1'
|
51
|
+
assert data.output_filename == ''
|
52
|
+
assert data.index_of_image_in_current_image_list == '0'
|
53
|
+
assert data.quantum_depth == '16'
|
54
|
+
assert data.image_class_and_colorspace == 'DirectClass sRGB Matte'
|
55
|
+
assert data.scene_number == '0'
|
56
|
+
assert data.filename_without_directory_or_extension == 'rails'
|
57
|
+
assert data.unique_temporary_filename == ''
|
58
|
+
assert data.current_width_in_pixels == '50'
|
59
|
+
assert data.x_resolution_density == '72 Undefined'
|
60
|
+
assert data.y_resolution_density == '72 Undefined'
|
61
|
+
assert data.image_depth == '8'
|
62
|
+
assert data.image_transparency_channel_enabled == 'True'
|
63
|
+
assert data.image_compression_type == 'Zip'
|
64
|
+
assert data.image_gif_dispose_method == 'Undefined'
|
65
|
+
assert data.image_size_w_x_h == '50x64'
|
66
|
+
assert data.page_canvas_height == '64'
|
67
|
+
assert data.magick_filename =~ /\.*\/magick-metadata\/test\/rails.png/
|
68
|
+
assert data.page_canvas_offset == '+0+0'
|
69
|
+
assert data.page_canvas_size == '50x64'
|
70
|
+
assert data.image_compression_quality == '0'
|
71
|
+
assert data.scenes == '2147483647'
|
72
|
+
assert data.image_time_delay == '0'
|
73
|
+
assert data.page_canvas_width == '50'
|
74
|
+
assert data.page_canvas_x_offset == '0'
|
75
|
+
assert data.page_canvas_y_offset == '0'
|
76
|
+
assert data.unique_filename == ''
|
77
|
+
assert data.calculated_trim_bounding_box == '50x64+0+0'
|
78
|
+
assert data.calculated_signature_hash_of_image_values == 'ae231a37d573c2ef941f3345932183b58cf5c0e6a569839d931b6172cebdbe27'
|
79
|
+
```
|
80
|
+
|
81
|
+
## Testing
|
82
|
+
|
83
|
+
The gem is fully tested using [MicroTest](http://hopsoft.github.com/micro_test/). Use the command `mt` to perform the tests.
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
1. Fork it
|
88
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
89
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
90
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
91
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,113 @@
|
|
1
|
+
class MagickMetadata
|
2
|
+
|
3
|
+
def initialize( file_path )
|
4
|
+
|
5
|
+
# Create attr_accessors for all keys in the data_map
|
6
|
+
data_map.each do |k, v|
|
7
|
+
create_attr v
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get the data for the image using 'identify'
|
11
|
+
format_str = data_map.keys.map{|k|"%#{k}"}.join('|')
|
12
|
+
data = %x[identify -format "#{format_str}" #{file_path}].chomp
|
13
|
+
|
14
|
+
# Parse the data response and assign it to the instance values
|
15
|
+
data.split('|').each_with_index do |val, idx|
|
16
|
+
attr_name = data_map.values[idx]
|
17
|
+
instance_variable_set("@#{attr_name}", val)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
# Helper methods
|
23
|
+
|
24
|
+
def has_transparency?
|
25
|
+
@image_transparency_channel_enabled == 'True'
|
26
|
+
end
|
27
|
+
|
28
|
+
def dimensions
|
29
|
+
[@current_width_in_pixels.to_i, @current_height_in_pixels.to_i]
|
30
|
+
end
|
31
|
+
|
32
|
+
def file_size
|
33
|
+
@file_size_of_image.scan(/\d/).join().to_i if @file_size_of_image
|
34
|
+
end
|
35
|
+
|
36
|
+
def resolution
|
37
|
+
@x_resolution_density.scan(/\d/).join().to_i if @x_resolution_density
|
38
|
+
end
|
39
|
+
|
40
|
+
def compression_percent
|
41
|
+
@image_compression_quality.to_f if @image_compression_quality
|
42
|
+
end
|
43
|
+
|
44
|
+
def width
|
45
|
+
dimensions[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
def height
|
49
|
+
dimensions[1]
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def data_map
|
55
|
+
{
|
56
|
+
'b' => 'file_size_of_image',
|
57
|
+
'c' => 'comment',
|
58
|
+
'd' => 'directory',
|
59
|
+
'e' => 'filename_suffix',
|
60
|
+
'f' => 'filename_with_suffix',
|
61
|
+
'g' => 'layer_canvas_page_geometry',
|
62
|
+
'h' => 'current_height_in_pixels',
|
63
|
+
'i' => 'image_filename',
|
64
|
+
'k' => 'calculated_number_of_unique_colors',
|
65
|
+
'l' => 'label',
|
66
|
+
'm' => 'image_file_format',
|
67
|
+
'n' => 'number_of_images_in_current_image_sequence',
|
68
|
+
'o' => 'output_filename',
|
69
|
+
'p' => 'index_of_image_in_current_image_list',
|
70
|
+
'q' => 'quantum_depth',
|
71
|
+
'r' => 'image_class_and_colorspace',
|
72
|
+
's' => 'scene_number',
|
73
|
+
't' => 'filename_without_directory_or_extension',
|
74
|
+
'u' => 'unique_temporary_filename',
|
75
|
+
'w' => 'current_width_in_pixels',
|
76
|
+
'x' => 'x_resolution_density',
|
77
|
+
'y' => 'y_resolution_density',
|
78
|
+
'z' => 'image_depth',
|
79
|
+
'A' => 'image_transparency_channel_enabled',
|
80
|
+
'C' => 'image_compression_type',
|
81
|
+
'D' => 'image_gif_dispose_method',
|
82
|
+
'G' => 'image_size_w_x_h',
|
83
|
+
'H' => 'page_canvas_height',
|
84
|
+
'M' => 'magick_filename',
|
85
|
+
'O' => 'page_canvas_offset',
|
86
|
+
'P' => 'page_canvas_size',
|
87
|
+
'Q' => 'image_compression_quality',
|
88
|
+
'S' => 'scenes',
|
89
|
+
'T' => 'image_time_delay',
|
90
|
+
'W' => 'page_canvas_width',
|
91
|
+
'X' => 'page_canvas_x_offset',
|
92
|
+
'Y' => 'page_canvas_y_offset',
|
93
|
+
'Z' => 'unique_filename',
|
94
|
+
'@' => 'calculated_trim_bounding_box',
|
95
|
+
'#' => 'calculated_signature_hash_of_image_values'
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_method( name, &block )
|
100
|
+
self.class.send( :define_method, name, &block )
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_attr( name )
|
104
|
+
create_method( "#{name}=".to_sym ) { |val|
|
105
|
+
instance_variable_set( "@" + name, val)
|
106
|
+
}
|
107
|
+
|
108
|
+
create_method( name.to_sym ) {
|
109
|
+
instance_variable_get( "@" + name )
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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 = "magick-metadata"
|
7
|
+
gem.version = "0.0.3"
|
8
|
+
gem.authors = ["Eric Berry"]
|
9
|
+
gem.email = ["cavneb@gmail.com"]
|
10
|
+
gem.description = %q{Parses an image using ImageMagick and parses the metadata}
|
11
|
+
gem.summary = %q{Parses an image using ImageMagick and parses the metadata}
|
12
|
+
gem.homepage = "http://github.com/cavneb/magick-metadata"
|
13
|
+
|
14
|
+
gem.add_development_dependency "micro_test"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class MagickMetadataTest < 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 = ::MagickMetadata.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 =~ /\.*\/magick-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 =~ /\.*\/magick-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 =~ /\.*\/magick-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
|
data/test/rails.png
ADDED
Binary file
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magick-metadata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Berry
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: micro_test
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
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
|
+
description: Parses an image using ImageMagick and parses the metadata
|
31
|
+
email:
|
32
|
+
- cavneb@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/magick-metadata.rb
|
43
|
+
- magick-metadata.gemspec
|
44
|
+
- test/magick_metadata_test.rb
|
45
|
+
- test/rails.png
|
46
|
+
- test/test_helper.rb
|
47
|
+
homepage: http://github.com/cavneb/magick-metadata
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Parses an image using ImageMagick and parses the metadata
|
71
|
+
test_files:
|
72
|
+
- test/magick_metadata_test.rb
|
73
|
+
- test/rails.png
|
74
|
+
- test/test_helper.rb
|