file_data 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +27 -25
- data/lib/file_data/formats/exif/exif.rb +8 -7
- data/lib/file_data/formats/exif/exif_reader.rb +25 -21
- data/lib/file_data/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d38cf3da31fc0fc355f64228574f06888f52563e
|
4
|
+
data.tar.gz: 6babcaa52b7fe146f4a310eb2eb34868522edd2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f537057f31aa2f9021cdf9f9d75a94fb03024f2e9b796f99c56a26c3826a7b801931771e73ffecdee4492050eb57fc320403b8007dbda3403317af577b95428b
|
7
|
+
data.tar.gz: 4ffd9045d319937d8b2561ee046eca8e6a08ca6cadcf938f4a3a132ec872aca310645c8b7a517ef6ed7e8f4f1793e9736fc3483010fd9a18ddaf87ab4635e596
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,40 +20,42 @@ To read exif data a stream of the jpeg data should be used as input. For perform
|
|
20
20
|
Examples:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
|
23
|
+
## Get Exif data from a file path or stream
|
24
24
|
|
25
|
-
#
|
26
|
-
|
25
|
+
# The file path or stream is passed as a parameter to class methods on FileData::Exif
|
26
|
+
# rather than having the file path or stream set in the constructor and the methods
|
27
|
+
# be instance methods to ensure that the user falls into a "pit of success" by only
|
28
|
+
# opening the file once to get tag values rather than potentially multiple times
|
27
29
|
|
28
|
-
#
|
30
|
+
# Get image exif data from a file path...
|
31
|
+
hash = FileData::Exif.image_data_only('/path/to/file.jpg')
|
32
|
+
|
33
|
+
# Get thumbnail exif data from a file stream...
|
29
34
|
File.open('/path/to/file.jpg', 'rb') do |f|
|
30
|
-
hash = FileData::Exif.
|
35
|
+
hash = FileData::Exif.thumbnail_data_only(f)
|
31
36
|
end
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
## Commands that get multiple tag values
|
36
|
-
|
37
|
-
# Get only the image Exif data
|
38
|
-
hash = FileData::Exif.new.image_data_only(file_path_or_stream)
|
39
|
-
|
40
|
-
# Get only the thumbnail Exif data
|
41
|
-
hash = FileData::Exif.new.thumbnail_data_only(file_path_or_stream)
|
38
|
+
## Extract values depending on how much data is returned
|
42
39
|
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
40
|
+
# Image and thumbnail data are returned as a hash with keys
|
41
|
+
# being the full tag name if it exists in FileData::ExifTags (see below listing)
|
42
|
+
# or "#{ifd_id}-#{tag_id}" if there is no existing name for the tag in FileData::ExifTags
|
43
|
+
image_hash = FileData::Exif.image_data_only(file_path_or_stream)
|
44
|
+
image_description_value = image_hash[:Other_ImageDescription]
|
45
|
+
unknown_gps_tag_value = image_hash["34853-99999"]
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# all FileData::ExifTags.tag_groups keys are given after the examples
|
47
|
+
thumbnail_hash = FileData::Exif.thumbnail_data_only(file_path_or_stream)
|
48
|
+
image_width_tag_value = thumbnail_hash[:Image_Structure_Width]
|
49
|
+
unknown_gps_tag_value = thumbnail_hash["Tiff-99999"]
|
51
50
|
|
52
|
-
|
53
|
-
|
51
|
+
all_data = FileData::Exif.all_data(file_path_or_stream)
|
52
|
+
image_hash = all_data.image
|
53
|
+
thumbnail_hash = all_data.thumbnail
|
54
54
|
|
55
|
-
#
|
56
|
-
|
55
|
+
# For extracting only a specific tag the value is returned and the search key must be
|
56
|
+
# an array matching the keys needed to get traverse FileData:ExifTags (see below listing)
|
57
|
+
image_description_value = FileData::Exif.only_image_tag(file_path_or_stream, [:Tiff, 270])
|
58
|
+
unknown_exif_tag_value = FileData::Exif.only_thumbnail_tag(file_path_or_stream, [34665, 2])
|
57
59
|
```
|
58
60
|
|
59
61
|
## Known Tag Keys
|
@@ -5,22 +5,23 @@ module FileData
|
|
5
5
|
# Convenience class for extracting exif data from a file or stream
|
6
6
|
class Exif
|
7
7
|
# Create methods that forward to ExifReader
|
8
|
-
|
9
|
-
|
8
|
+
# Each method requires the stream as a parameter to help the user
|
9
|
+
# fall into a "pit of success" by only opening and closing
|
10
|
+
# the stream once to get data
|
11
|
+
ExifReader.public_instance_methods(false).each do |method_name|
|
12
|
+
define_singleton_method(method_name) do |input, *other_args|
|
10
13
|
delegate_to_exif_reader(input, method_name, other_args)
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
def delegate_to_exif_reader(input, name, other_args)
|
17
|
+
def self.delegate_to_exif_reader(input, name, other_args)
|
17
18
|
streamify(input) do |stream|
|
18
19
|
exif = ExifJpeg.new(stream).exif
|
19
|
-
ExifReader.new.send(name,
|
20
|
+
ExifReader.new(exif).send(name, *other_args)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
def streamify(input)
|
24
|
+
def self.streamify(input)
|
24
25
|
if input.is_a?(String)
|
25
26
|
File.open(input, 'rb') { |f| yield f }
|
26
27
|
else
|
@@ -6,47 +6,51 @@ require_relative 'exif_data'
|
|
6
6
|
module FileData
|
7
7
|
# Returns the exif data from a jpeg file
|
8
8
|
class ExifReader
|
9
|
-
def
|
10
|
-
|
9
|
+
def initialize(exif_stream)
|
10
|
+
@exif_stream = exif_stream
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
exif_tags_internal(
|
13
|
+
def image_data_only
|
14
|
+
exif_tags_internal(0).image
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
exif_tags_internal(
|
17
|
+
def thumbnail_data_only
|
18
|
+
exif_tags_internal(1).thumbnail
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def all_data
|
22
|
+
exif_tags_internal(0, 1)
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
exif_tag_internal(
|
25
|
+
def only_image_tag(tag_id)
|
26
|
+
exif_tag_internal(0, tag_id)
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def only_thumbnail_tag(tag_id)
|
30
|
+
exif_tag_internal(1, tag_id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def tags(*ifds_to_include)
|
34
|
+
return [] if @exif_stream.nil?
|
31
35
|
|
32
|
-
exif_stream.read_header
|
33
|
-
ExifTagReader.new(exif_stream, *ifds_to_include).tags
|
36
|
+
@exif_stream.read_header
|
37
|
+
ExifTagReader.new(@exif_stream, *ifds_to_include).tags
|
34
38
|
end
|
35
39
|
|
36
40
|
private
|
37
41
|
|
38
|
-
def exif_tags_internal(
|
39
|
-
tags(exif_stream, *ifds_to_include).each_with_object(ExifData.new) do |tag_info, data|
|
40
|
-
data.add_tag(*tag_info, exif_stream.read_tag_value)
|
42
|
+
def exif_tags_internal(*ifds_to_include)
|
43
|
+
tags(@exif_stream, *ifds_to_include).each_with_object(ExifData.new) do |tag_info, data|
|
44
|
+
data.add_tag(*tag_info, @exif_stream.read_tag_value)
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
def exif_tag_internal(
|
45
|
-
exif_stream.read_tag_value if find_tag(
|
48
|
+
def exif_tag_internal(ifd_index, tag_to_find)
|
49
|
+
@exif_stream.read_tag_value if find_tag(ifd_index, tag_to_find)
|
46
50
|
end
|
47
51
|
|
48
|
-
def find_tag(
|
49
|
-
tags(exif_stream, ifd_index).find do |_, ifd_id, tag_num|
|
52
|
+
def find_tag(ifd_index, tag_to_find)
|
53
|
+
tags(@exif_stream, ifd_index).find do |_, ifd_id, tag_num|
|
50
54
|
tag_to_find == [ifd_id, tag_num]
|
51
55
|
end
|
52
56
|
end
|
data/lib/file_data/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|