image_voodoo 0.8.7 → 0.8.8
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 +4 -4
- data/.travis.yml +2 -0
- data/LICENSE-2.0.txt +202 -0
- data/README.exif +18 -0
- data/README.md +1 -0
- data/Rakefile +11 -0
- data/bin/image_voodoo +26 -6
- data/lib/image_voodoo.rb +40 -4
- data/lib/image_voodoo/awt.rb +57 -14
- data/lib/image_voodoo/gae.rb +1 -1
- data/lib/image_voodoo/metadata.rb +1641 -0
- data/lib/image_voodoo/version.rb +1 -1
- data/test/test_metadata.rb +50 -0
- data/tools/gen.rb +61 -0
- data/vendor/metadata-extractor-2.7.0.jar +0 -0
- data/vendor/xmpcore-5.1.2.jar +0 -0
- metadata +13 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10db8a256e32e37a28b94c9246049f7029484a49
|
|
4
|
+
data.tar.gz: 27ec82a19aff0bc3171a2c0bff8338c1c7ef19e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bf960b9cd108f06ea22ba69a5f01f7d5ee3ca10dec63fe7a79cf6d2fe986f9a6753ef1969c8eabfa95af8509e0b19211b6ea7c0718d6106c42d998e255e6e36
|
|
7
|
+
data.tar.gz: 27e8b1a524c25f7a72b3b15c3a9e37e4bf983111410a8be64d78b45c55ce133ed185ec5cf47ab527b565828d106515fdf053ccc41ee0298b1b1b6df75fc923f3
|
data/.travis.yml
ADDED
data/LICENSE-2.0.txt
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README.exif
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright 2002-2012 Drew Noakes
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
More information about this project is available at:
|
|
16
|
+
|
|
17
|
+
http://drewnoakes.com/code/exif/
|
|
18
|
+
http://code.google.com/p/metadata-extractor/
|
data/README.md
CHANGED
|
@@ -13,6 +13,7 @@ http://github.com/jruby/image_voodoo
|
|
|
13
13
|
* Includes image_voodoo command-line utility for quick resizing of images, "image_voodoo --help" for usage.
|
|
14
14
|
* Due to lack of TIFF support in ImageIO it is also not supported yet by image_voodoo. If you need it, create an issue in GitHub.
|
|
15
15
|
* **JPEG CMYK support** is thanks to work of Werner Randelshofer and [Monte Media Library](http://www.randelshofer.ch/monte/). Monte Media Library is provided under [CC BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
|
|
16
|
+
* Now supports reading a variety of EXIF data. This also supports new function --orient based on how phones typically save photo data.
|
|
16
17
|
|
|
17
18
|
## SYNOPSIS:
|
|
18
19
|
|
data/Rakefile
CHANGED
data/bin/image_voodoo
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'optparse'
|
|
4
4
|
|
|
5
|
+
headless = true
|
|
5
6
|
actions = []
|
|
6
7
|
images = []
|
|
7
8
|
original_image = nil
|
|
@@ -59,14 +60,33 @@ opts = OptionParser.new do |opts|
|
|
|
59
60
|
actions << lambda {|img| img.flip_horizontally }
|
|
60
61
|
end
|
|
61
62
|
|
|
63
|
+
opts.on("-m", "--metadata") do
|
|
64
|
+
actions << lambda {|img| puts img.metadata }
|
|
65
|
+
end
|
|
66
|
+
|
|
62
67
|
opts.on("-n", "--negative", "Make a negative out of the image") do
|
|
63
68
|
actions << lambda {|img| img.negative }
|
|
64
69
|
end
|
|
65
70
|
|
|
71
|
+
opts.on("-o", "--orient", "Rotate image to orient it based on metadata") do
|
|
72
|
+
actions << lambda {|img| img.correct_orientation }
|
|
73
|
+
end
|
|
74
|
+
|
|
66
75
|
opts.on("-q", "--quality 0..1", Float, "Set % of quality for lossy compression") do |quality|
|
|
67
76
|
actions << lambda {|img| img.quality(quality) }
|
|
68
77
|
end
|
|
69
78
|
|
|
79
|
+
opts.on("-R", "--rotate 0..360", Float, "Set angle to rotate image") do |angle|
|
|
80
|
+
actions << lambda {|img| img.rotate(angle.to_f) }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
opts.on("-r", "--resize WIDTHxHEIGHT", "Create a new image with the specified", "dimensions") do |dim|
|
|
84
|
+
width, height = dim.split(/x/i).map {|v| v.to_i}
|
|
85
|
+
opts.usage "You need to specify proper dimensions" unless width && width > 0 && height && height > 0
|
|
86
|
+
actions << lambda {|img| img.resize(width,height) }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
70
90
|
opts.on("-s", "--save FILENAME", "Save the results to a new file") do |f|
|
|
71
91
|
actions << lambda {|img| img.save(f); img }
|
|
72
92
|
end
|
|
@@ -81,6 +101,8 @@ opts = OptionParser.new do |opts|
|
|
|
81
101
|
|
|
82
102
|
opts.on("-p", "--preview", "Preview the image. Close the frame window",
|
|
83
103
|
"to continue, or quit the application to", "abort the action pipeline") do
|
|
104
|
+
|
|
105
|
+
headless = false
|
|
84
106
|
actions << lambda do |img|
|
|
85
107
|
done = false
|
|
86
108
|
img.preview { done = true }
|
|
@@ -97,12 +119,6 @@ opts = OptionParser.new do |opts|
|
|
|
97
119
|
actions << lambda {|img| images.pop || original_image }
|
|
98
120
|
end
|
|
99
121
|
|
|
100
|
-
opts.on("-r", "--resize WIDTHxHEIGHT", "Create a new image with the specified", "dimensions") do |dim|
|
|
101
|
-
width, height = dim.split(/x/i).map {|v| v.to_i}
|
|
102
|
-
opts.usage "You need to specify proper dimensions" unless width && width > 0 && height && height > 0
|
|
103
|
-
actions << lambda {|img| img.resize(width,height) }
|
|
104
|
-
end
|
|
105
|
-
|
|
106
122
|
opts.on("-f", "--format", "Print the image format") do
|
|
107
123
|
actions << lambda {|img| puts img.format; img }
|
|
108
124
|
end
|
|
@@ -122,6 +138,10 @@ opts.parse!(ARGV)
|
|
|
122
138
|
opts.usage("You need to supply a source image filename.") unless ARGV.first
|
|
123
139
|
opts.usage("You need to supply one or more actions.") unless actions.size > 0
|
|
124
140
|
|
|
141
|
+
# For this binstub we only want to load non-headless if we are using
|
|
142
|
+
# the preview feature. top of See lib/image_voodoo.rb for more info...
|
|
143
|
+
class ImageVoodoo; NEEDS_HEAD = true; end unless headless
|
|
144
|
+
|
|
125
145
|
require 'image_voodoo'
|
|
126
146
|
file_name = ARGV.first
|
|
127
147
|
method = file_name =~ /^http:/ ? :from_url : :with_image
|
data/lib/image_voodoo.rb
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# Before we load image_voodoo we can specify whether we want it to load full
|
|
2
|
+
# AWT ala http://www.oracle.com/technetwork/articles/javase/headless-136834.html
|
|
3
|
+
# Most users are using image_voodoo as a library for manipulation and do not
|
|
4
|
+
# want a full peer window popping up.
|
|
5
|
+
unless defined? ImageVoodoo::NEEDS_HEAD
|
|
6
|
+
java.lang.System.set_property 'java.awt.headless', 'true'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
##
|
|
2
11
|
#
|
|
3
12
|
# = ImageVoodoo
|
|
@@ -44,9 +53,8 @@ class ImageVoodoo
|
|
|
44
53
|
require 'image_voodoo/awt'
|
|
45
54
|
end
|
|
46
55
|
|
|
47
|
-
def initialize(src, format=nil)
|
|
48
|
-
@src = src
|
|
49
|
-
@format = format
|
|
56
|
+
def initialize(io, src, format=nil)
|
|
57
|
+
@io, @src, @format = io, src, format
|
|
50
58
|
@quality = nil # nil means no specific quality ever specified
|
|
51
59
|
end
|
|
52
60
|
|
|
@@ -82,6 +90,17 @@ class ImageVoodoo
|
|
|
82
90
|
String.from_java_bytes java_bytes
|
|
83
91
|
end
|
|
84
92
|
|
|
93
|
+
##
|
|
94
|
+
# If current image was taken by a phone it might save the orientation
|
|
95
|
+
# in format it was physically taken and added IFD0 Orientation information
|
|
96
|
+
# instead of rotating it. This method will perform that rotation based
|
|
97
|
+
# on Orientation metadata.
|
|
98
|
+
#
|
|
99
|
+
def correct_orientation
|
|
100
|
+
target = guard { correct_orientation_impl }
|
|
101
|
+
block_given? ? yield(target) : target
|
|
102
|
+
end
|
|
103
|
+
|
|
85
104
|
##
|
|
86
105
|
#
|
|
87
106
|
# Creates a square thumbnail of the image cropping the longest edge to
|
|
@@ -124,6 +143,14 @@ class ImageVoodoo
|
|
|
124
143
|
end
|
|
125
144
|
alias_method :grayscale, :greyscale
|
|
126
145
|
|
|
146
|
+
##
|
|
147
|
+
#
|
|
148
|
+
# Extracts metadata from an image.
|
|
149
|
+
#
|
|
150
|
+
def metadata
|
|
151
|
+
guard { metadata_impl }
|
|
152
|
+
end
|
|
153
|
+
|
|
127
154
|
##
|
|
128
155
|
#
|
|
129
156
|
# Creates a negative and yields/returns the new image.
|
|
@@ -159,6 +186,15 @@ class ImageVoodoo
|
|
|
159
186
|
raise ArgumentError, ne.message
|
|
160
187
|
end
|
|
161
188
|
|
|
189
|
+
##
|
|
190
|
+
#
|
|
191
|
+
# Rotates the image by angle (specified in degrees).
|
|
192
|
+
#
|
|
193
|
+
def rotate(angle)
|
|
194
|
+
target = guard { rotate_impl(angle) }
|
|
195
|
+
block_given? ? yield(target) : target
|
|
196
|
+
end
|
|
197
|
+
|
|
162
198
|
##
|
|
163
199
|
#
|
|
164
200
|
# Saves the image out to path. Changing the file extension will convert
|
|
@@ -208,7 +244,7 @@ class ImageVoodoo
|
|
|
208
244
|
# A top-level image loader opens path and then yields/returns the image.
|
|
209
245
|
#
|
|
210
246
|
def self.with_image(path)
|
|
211
|
-
raise ArgumentError, "file does not exist" unless File.file?(path)
|
|
247
|
+
raise ArgumentError, "file does not exist: #{path}" unless File.file?(path)
|
|
212
248
|
image = guard { with_image_impl(JFile.new(path)) }
|
|
213
249
|
image && block_given? ? yield(image) : image
|
|
214
250
|
end
|
data/lib/image_voodoo/awt.rb
CHANGED
|
@@ -20,10 +20,6 @@ class ImageVoodoo
|
|
|
20
20
|
java_import javax.swing.JFrame
|
|
21
21
|
java_import javax.imageio.IIOException
|
|
22
22
|
|
|
23
|
-
require 'CMYKDemo.jar'
|
|
24
|
-
java_import org.monte.media.jpeg.CMYKJPEGImageReader
|
|
25
|
-
java_import org.monte.media.jpeg.CMYKJPEGImageReaderSpi
|
|
26
|
-
|
|
27
23
|
# FIXME: Move and rewrite in terms of new shape
|
|
28
24
|
##
|
|
29
25
|
#
|
|
@@ -105,7 +101,7 @@ class ImageVoodoo
|
|
|
105
101
|
def paint(src=dup_src)
|
|
106
102
|
yield src.graphics
|
|
107
103
|
src.graphics.dispose
|
|
108
|
-
ImageVoodoo.new(src, @format)
|
|
104
|
+
ImageVoodoo.new(@io, src, @format)
|
|
109
105
|
end
|
|
110
106
|
|
|
111
107
|
##
|
|
@@ -132,7 +128,7 @@ class ImageVoodoo
|
|
|
132
128
|
# *AWT* Create an image of width x height filled with a single color.
|
|
133
129
|
#
|
|
134
130
|
def self.canvas(width, height, rgb='000000')
|
|
135
|
-
image = ImageVoodoo.new(BufferedImage.new(width, height, ARGB))
|
|
131
|
+
image = ImageVoodoo.new(@io, BufferedImage.new(width, height, ARGB))
|
|
136
132
|
image.rect(0, 0, width, height, rgb)
|
|
137
133
|
end
|
|
138
134
|
|
|
@@ -147,15 +143,18 @@ class ImageVoodoo
|
|
|
147
143
|
def self.with_image_impl(file)
|
|
148
144
|
format = detect_format_from_input(file)
|
|
149
145
|
buffered_image = read_image_from_input(file)
|
|
150
|
-
buffered_image ? ImageVoodoo.new(buffered_image, format) : nil
|
|
146
|
+
buffered_image ? ImageVoodoo.new(file, buffered_image, format) : nil
|
|
151
147
|
end
|
|
152
148
|
|
|
153
149
|
def self.read_image_from_input(input)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
ImageIO.read(input)
|
|
151
|
+
rescue IIOException
|
|
152
|
+
require 'CMYKDemo.jar'
|
|
153
|
+
|
|
154
|
+
cmyk_spi = org.monte.media.jpeg.CMYKJPEGImageReaderSpi.new
|
|
155
|
+
cmyk_reader = org.monte.media.jpeg.CMYKJPEGImageReader.new cmyk_spi
|
|
156
|
+
cmyk_reader.input = ImageIO.createImageInputStream(input)
|
|
157
|
+
cmyk_reader.read 0
|
|
159
158
|
end
|
|
160
159
|
|
|
161
160
|
def self.detect_format_from_input(input)
|
|
@@ -168,7 +167,9 @@ class ImageVoodoo
|
|
|
168
167
|
input_stream = ByteArrayInputStream.new(bytes)
|
|
169
168
|
format = detect_format_from_input(input_stream)
|
|
170
169
|
input_stream.reset
|
|
171
|
-
|
|
170
|
+
buffered_image = read_image_from_input(input_stream)
|
|
171
|
+
input_stream.reset
|
|
172
|
+
ImageVoodoo.new(input_stream, buffered_image, format)
|
|
172
173
|
end
|
|
173
174
|
|
|
174
175
|
#
|
|
@@ -229,6 +230,27 @@ class ImageVoodoo
|
|
|
229
230
|
out.to_byte_array
|
|
230
231
|
end
|
|
231
232
|
|
|
233
|
+
def correct_orientation_impl
|
|
234
|
+
case metadata.orientation
|
|
235
|
+
when 2 then
|
|
236
|
+
flip_horizontally
|
|
237
|
+
when 3 then
|
|
238
|
+
rotate 180
|
|
239
|
+
when 4 then
|
|
240
|
+
flip_vertically
|
|
241
|
+
when 5 then
|
|
242
|
+
flip_horizontally
|
|
243
|
+
rotate 270
|
|
244
|
+
when 6 then
|
|
245
|
+
rotate 90
|
|
246
|
+
when 7 then
|
|
247
|
+
flip_horizontally
|
|
248
|
+
rotate 270
|
|
249
|
+
else
|
|
250
|
+
self
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
232
254
|
def flip_horizontally_impl
|
|
233
255
|
paint {|g| g.draw_image @src, 0, 0, width, height, width, 0, 0, height, nil}
|
|
234
256
|
end
|
|
@@ -241,6 +263,12 @@ class ImageVoodoo
|
|
|
241
263
|
transform(GREY_OP)
|
|
242
264
|
end
|
|
243
265
|
|
|
266
|
+
def metadata_impl
|
|
267
|
+
require 'image_voodoo/metadata'
|
|
268
|
+
|
|
269
|
+
@metadata ||= ImageVoodoo::Metadata.new(@io)
|
|
270
|
+
end
|
|
271
|
+
|
|
244
272
|
def negative_impl
|
|
245
273
|
transform(NEGATIVE_OP)
|
|
246
274
|
end
|
|
@@ -252,6 +280,21 @@ class ImageVoodoo
|
|
|
252
280
|
end
|
|
253
281
|
end
|
|
254
282
|
|
|
283
|
+
def rotate_impl(degrees)
|
|
284
|
+
radians = degrees * Math::PI / 180
|
|
285
|
+
sin, cos = Math.sin(radians).abs, Math.cos(radians).abs
|
|
286
|
+
new_width = (width * cos + height * sin).floor
|
|
287
|
+
new_height = (width * sin + height * cos).floor
|
|
288
|
+
|
|
289
|
+
paint(BufferedImage.new(new_width, new_height, color_type)) do |g|
|
|
290
|
+
|
|
291
|
+
g.java_send :translate, [::Java::int, ::Java::int],
|
|
292
|
+
(new_width - width)/2, (new_height - height)/2
|
|
293
|
+
g.rotate(radians, width / 2, height / 2);
|
|
294
|
+
g.draw_image @src, 0, 0, nil
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
255
298
|
#
|
|
256
299
|
# Save using the format string (jpg, gif, etc..) to the open Java File
|
|
257
300
|
# instance passed in.
|
|
@@ -261,7 +304,7 @@ class ImageVoodoo
|
|
|
261
304
|
end
|
|
262
305
|
|
|
263
306
|
def with_crop_impl(left, top, right, bottom)
|
|
264
|
-
ImageVoodoo.new(@src.get_subimage(left, top, right-left, bottom-top), @format)
|
|
307
|
+
ImageVoodoo.new(@io, @src.get_subimage(left, top, right-left, bottom-top), @format)
|
|
265
308
|
end
|
|
266
309
|
|
|
267
310
|
def write_new_image(format, stream)
|