image_paradise 0.1.12
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.
Potentially problematic release.
This version of image_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/LICENSE.md +38 -0
- data/README.md +179 -0
- data/USAGE.md +10 -0
- data/bin/black_white +10 -0
- data/bin/display_text_from_this_image +7 -0
- data/bin/image_paradise +7 -0
- data/bin/image_paradise_shell +7 -0
- data/bin/image_to_ascii +54 -0
- data/bin/image_to_pdf +7 -0
- data/bin/make_this_image_transparent +7 -0
- data/bin/rotate_left +7 -0
- data/bin/rotate_right +7 -0
- data/doc/README.gen +162 -0
- data/doc/TODO_FOR_THE_GTK_GUI.md +1 -0
- data/image_paradise.gemspec +50 -0
- data/lib/image_paradise.rb +5 -0
- data/lib/image_paradise/base/base.rb +91 -0
- data/lib/image_paradise/black_white.rb +89 -0
- data/lib/image_paradise/confree_generator/class.rb +614 -0
- data/lib/image_paradise/confree_generator/constants.rb +61 -0
- data/lib/image_paradise/confree_generator/gui/gtk_confree_generator.rb +752 -0
- data/lib/image_paradise/confree_generator/gui/insert_button.rb +78 -0
- data/lib/image_paradise/confree_generator/reset.rb +61 -0
- data/lib/image_paradise/confree_generator/shared/shared.rb +100 -0
- data/lib/image_paradise/constants.rb +43 -0
- data/lib/image_paradise/constants/image_file_types.rb +21 -0
- data/lib/image_paradise/create_animated_gif.rb +47 -0
- data/lib/image_paradise/crop/crop.rb +302 -0
- data/lib/image_paradise/gm_support.rb +34 -0
- data/lib/image_paradise/graphs.rb +36 -0
- data/lib/image_paradise/graphs/accumulator_bar.rb +29 -0
- data/lib/image_paradise/graphs/area.rb +64 -0
- data/lib/image_paradise/graphs/bar.rb +117 -0
- data/lib/image_paradise/graphs/bar_conversion.rb +53 -0
- data/lib/image_paradise/graphs/base.rb +1392 -0
- data/lib/image_paradise/graphs/bezier.rb +45 -0
- data/lib/image_paradise/graphs/bullet.rb +115 -0
- data/lib/image_paradise/graphs/deprecated.rb +42 -0
- data/lib/image_paradise/graphs/dot.rb +129 -0
- data/lib/image_paradise/graphs/line.rb +328 -0
- data/lib/image_paradise/graphs/mini/bar.rb +42 -0
- data/lib/image_paradise/graphs/mini/legend.rb +109 -0
- data/lib/image_paradise/graphs/mini/pie.rb +42 -0
- data/lib/image_paradise/graphs/mini/side_bar.rb +41 -0
- data/lib/image_paradise/graphs/net.rb +133 -0
- data/lib/image_paradise/graphs/photo_bar.rb +106 -0
- data/lib/image_paradise/graphs/pie.rb +139 -0
- data/lib/image_paradise/graphs/scatter.rb +264 -0
- data/lib/image_paradise/graphs/scene.rb +216 -0
- data/lib/image_paradise/graphs/side_bar.rb +144 -0
- data/lib/image_paradise/graphs/side_stacked_bar.rb +116 -0
- data/lib/image_paradise/graphs/spider.rb +163 -0
- data/lib/image_paradise/graphs/stacked_area.rb +73 -0
- data/lib/image_paradise/graphs/stacked_bar.rb +68 -0
- data/lib/image_paradise/graphs/stacked_mixin.rb +30 -0
- data/lib/image_paradise/graphs/themes.rb +117 -0
- data/lib/image_paradise/graphviz/README.md +2 -0
- data/lib/image_paradise/graphviz/generate_graphviz_image.rb +274 -0
- data/lib/image_paradise/gui/gtk/control_panel.rb +126 -0
- data/lib/image_paradise/identify.rb +145 -0
- data/lib/image_paradise/image_border.rb +231 -0
- data/lib/image_paradise/image_manipulations.rb +320 -0
- data/lib/image_paradise/image_paradise.rb +150 -0
- data/lib/image_paradise/image_to_ascii/image_to_ascii.rb +187 -0
- data/lib/image_paradise/image_to_pdf/image_to_pdf.rb +99 -0
- data/lib/image_paradise/label/README.md +2 -0
- data/lib/image_paradise/label/simple_label.rb +206 -0
- data/lib/image_paradise/optimizer.rb +483 -0
- data/lib/image_paradise/project/project.rb +29 -0
- data/lib/image_paradise/random_text_to_image.rb +363 -0
- data/lib/image_paradise/requires/common_base_requires.rb +17 -0
- data/lib/image_paradise/requires/require_colours.rb +9 -0
- data/lib/image_paradise/requires/require_gtk_components.rb +8 -0
- data/lib/image_paradise/requires/require_image_to_ascii.rb +7 -0
- data/lib/image_paradise/requires/require_the_image_paradise_project.rb +24 -0
- data/lib/image_paradise/requires/require_toplevel_methods.rb +21 -0
- data/lib/image_paradise/rotate/README.md +2 -0
- data/lib/image_paradise/rotate/rotate.rb +98 -0
- data/lib/image_paradise/shell/interactive.rb +156 -0
- data/lib/image_paradise/svg/README.md +5 -0
- data/lib/image_paradise/svg/circle.rb +106 -0
- data/lib/image_paradise/svg/feature.rb +48 -0
- data/lib/image_paradise/svg/rectangle.rb +154 -0
- data/lib/image_paradise/svg/svg.rb +102 -0
- data/lib/image_paradise/to_gif.rb +91 -0
- data/lib/image_paradise/to_jpg.rb +90 -0
- data/lib/image_paradise/toplevel_methods/add_black_border_to_this_image.rb +56 -0
- data/lib/image_paradise/toplevel_methods/crop.rb +28 -0
- data/lib/image_paradise/toplevel_methods/e.rb +16 -0
- data/lib/image_paradise/toplevel_methods/esystem.rb +19 -0
- data/lib/image_paradise/toplevel_methods/extract_text_from_this_image.rb +56 -0
- data/lib/image_paradise/toplevel_methods/file_related_code.rb +25 -0
- data/lib/image_paradise/toplevel_methods/flip_image_left_right.rb +32 -0
- data/lib/image_paradise/toplevel_methods/greyscale_this_image.rb +59 -0
- data/lib/image_paradise/toplevel_methods/help.rb +30 -0
- data/lib/image_paradise/toplevel_methods/make_this_image_transparent.rb +30 -0
- data/lib/image_paradise/toplevel_methods/menu.rb +92 -0
- data/lib/image_paradise/toplevel_methods/merge_these_images.rb +49 -0
- data/lib/image_paradise/toplevel_methods/mirror_image.rb +28 -0
- data/lib/image_paradise/toplevel_methods/misc.rb +31 -0
- data/lib/image_paradise/toplevel_methods/png_to_svg.rb +34 -0
- data/lib/image_paradise/toplevel_methods/roebe.rb +17 -0
- data/lib/image_paradise/toplevel_methods/to_png.rb +105 -0
- data/lib/image_paradise/toplevel_methods/wallpaper.rb +37 -0
- data/lib/image_paradise/toplevel_methods/write_this_text.rb +76 -0
- data/lib/image_paradise/version/version.rb +19 -0
- data/test/16x16_red_square_image_for_testing.png +0 -0
- data/test/testing_confree_generator.rb +8 -0
- data/test/testing_crop.rb +19 -0
- data/test/testing_image_magick_commands.rb +39 -0
- data/test/testing_image_paradise.rb +49 -0
- data/test/testing_the_svg_component.html +261 -0
- data/test/testing_the_svg_component.rb +106 -0
- metadata +217 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'image_paradise/image_manipulations.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
require 'image_paradise/gm_support.rb'
|
|
8
|
+
|
|
9
|
+
module ImageParadise
|
|
10
|
+
|
|
11
|
+
class ImageManipulations
|
|
12
|
+
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
# === initialize
|
|
15
|
+
#
|
|
16
|
+
# The first argument to this method should be the path to the file
|
|
17
|
+
# that we want to manipulate.
|
|
18
|
+
# ========================================================================= #
|
|
19
|
+
def initialize(i)
|
|
20
|
+
reset
|
|
21
|
+
set_file(i)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# ========================================================================= #
|
|
25
|
+
# === set_file
|
|
26
|
+
# ========================================================================= #
|
|
27
|
+
def set_file(i)
|
|
28
|
+
@file = i
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# ========================================================================= #
|
|
32
|
+
# === reset
|
|
33
|
+
# ========================================================================= #
|
|
34
|
+
def reset
|
|
35
|
+
@filename_changed = false
|
|
36
|
+
@display_sys_command = false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# ========================================================================= #
|
|
40
|
+
# === file?
|
|
41
|
+
# ========================================================================= #
|
|
42
|
+
def file?
|
|
43
|
+
@file
|
|
44
|
+
end; alias file file? # === file
|
|
45
|
+
|
|
46
|
+
# ========================================================================= #
|
|
47
|
+
# === identify
|
|
48
|
+
#
|
|
49
|
+
# Runs ImageMagick's 'identify'.
|
|
50
|
+
#
|
|
51
|
+
# See http://www.imagemagick.org/script/identify.php
|
|
52
|
+
# ========================================================================= #
|
|
53
|
+
def identify(i = {})
|
|
54
|
+
tokens = ['identify']
|
|
55
|
+
tokens << expand_arguments_to_key_value_pairs(i) if i
|
|
56
|
+
tokens << " '#{@file}#{"[#{i[:layer].to_s}]" if i[:layer]}'"
|
|
57
|
+
tokens = convert_to_command(tokens)
|
|
58
|
+
output = run_command(tokens).first
|
|
59
|
+
output
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# ========================================================================= #
|
|
63
|
+
# === dimensions
|
|
64
|
+
#
|
|
65
|
+
# Return the x and y dimensions of an image, as a Hash.
|
|
66
|
+
# ========================================================================= #
|
|
67
|
+
def dimensions
|
|
68
|
+
dimensions = identify( # Tap into Imagemagick's identify binary.
|
|
69
|
+
:layer => 0, :format => "%wx%h"
|
|
70
|
+
).chomp.split('x')
|
|
71
|
+
hash = {
|
|
72
|
+
x: dimensions[0].to_i,
|
|
73
|
+
y: dimensions[1].to_i
|
|
74
|
+
}
|
|
75
|
+
return hash
|
|
76
|
+
end; alias width_and_height dimensions # === width_and_height
|
|
77
|
+
|
|
78
|
+
# ========================================================================= #
|
|
79
|
+
# === width
|
|
80
|
+
#
|
|
81
|
+
# Returns the x dimension of an image as an integer
|
|
82
|
+
# ========================================================================= #
|
|
83
|
+
def width
|
|
84
|
+
dimensions[:x]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# ========================================================================= #
|
|
88
|
+
# === height
|
|
89
|
+
#
|
|
90
|
+
# Returns the y dimension of an image as an integer
|
|
91
|
+
# ========================================================================= #
|
|
92
|
+
def height
|
|
93
|
+
dimensions[:y]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# ========================================================================= #
|
|
97
|
+
# === montage
|
|
98
|
+
#
|
|
99
|
+
# Runs ImageMagick's 'montage'.
|
|
100
|
+
#
|
|
101
|
+
# See http://www.imagemagick.org/script/montage.php
|
|
102
|
+
# ========================================================================= #
|
|
103
|
+
def montage(sources, i = {})
|
|
104
|
+
tokens = ['montage']
|
|
105
|
+
tokens << expand_arguments_to_key_value_pairs(i) if i
|
|
106
|
+
sources.each {|source| tokens << " '#{source}'" }
|
|
107
|
+
tokens << " '#{@file}'"
|
|
108
|
+
tokens = convert_to_command(tokens)
|
|
109
|
+
success = run_command(tokens)[1]
|
|
110
|
+
success
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# ========================================================================= #
|
|
114
|
+
# === filename_changed?
|
|
115
|
+
# ========================================================================= #
|
|
116
|
+
def filename_changed?
|
|
117
|
+
@filename_changed
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# ========================================================================= #
|
|
121
|
+
# === do_manipulate
|
|
122
|
+
#
|
|
123
|
+
# Runs ImageMagick's 'mogrify' command. The first argument to this
|
|
124
|
+
# method is an (optional) Hash.
|
|
125
|
+
#
|
|
126
|
+
# See http://www.imagemagick.org/script/mogrify.php
|
|
127
|
+
#
|
|
128
|
+
# Invocation example:
|
|
129
|
+
# image.do_manipulate(scale: '80%') # => true
|
|
130
|
+
# ========================================================================= #
|
|
131
|
+
def do_manipulate(i = {})
|
|
132
|
+
tokens = ['mogrify']
|
|
133
|
+
tokens << expand_arguments_to_key_value_pairs(i) if i
|
|
134
|
+
tokens << " '#{@file}#{"[#{i[:layer].to_s}]" if i[:layer]}'"
|
|
135
|
+
tokens << " -annotate #{i[:annotate].to_s}" if i[:annotate]
|
|
136
|
+
tokens = convert_to_command(tokens)
|
|
137
|
+
success = run_command(tokens)[1]
|
|
138
|
+
replace_file(i[:format].to_s.downcase, i[:layer]) if success && i[:format]
|
|
139
|
+
success
|
|
140
|
+
end; alias manipulate! do_manipulate # === manipulate!
|
|
141
|
+
|
|
142
|
+
# ========================================================================= #
|
|
143
|
+
# === shrink
|
|
144
|
+
#
|
|
145
|
+
# Shrinks the given image at hand. Be careful with this method - it
|
|
146
|
+
# will instantly shrink the given file, without keeping a backup. So
|
|
147
|
+
# if you want to keep a backup, you have to copy the image file on
|
|
148
|
+
# your own BEFORE invoking this method here.
|
|
149
|
+
# ========================================================================= #
|
|
150
|
+
def shrink(n_percent = '80%')
|
|
151
|
+
unless n_percent.is_a? String
|
|
152
|
+
n_percent = n_percent.to_s
|
|
153
|
+
end
|
|
154
|
+
n_percent << '%' unless n_percent.end_with? '%'
|
|
155
|
+
do_manipulate(scale: n_percent)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# ========================================================================= #
|
|
159
|
+
# === replace_file
|
|
160
|
+
#
|
|
161
|
+
# Replaces the old file (with the old file format) with the newly
|
|
162
|
+
# generated one.
|
|
163
|
+
#
|
|
164
|
+
# The old file will be deleted and $file will be reset.
|
|
165
|
+
#
|
|
166
|
+
# If ImageMagick generated more than one file, $file will have a "*",
|
|
167
|
+
# so that all files generated will be manipulated in the following
|
|
168
|
+
# steps.
|
|
169
|
+
# ========================================================================= #
|
|
170
|
+
def replace_file(format, layer)
|
|
171
|
+
return if File.extname(@file) == format
|
|
172
|
+
|
|
173
|
+
layer ||= 0
|
|
174
|
+
layer = layer.split(',').first if layer.is_a? String
|
|
175
|
+
|
|
176
|
+
File.delete(@file)
|
|
177
|
+
|
|
178
|
+
@filename_changed = true
|
|
179
|
+
|
|
180
|
+
path = File.join File.dirname(@file), File.basename(@file, File.extname(@file))
|
|
181
|
+
new_file = find_file(path, format, layer)
|
|
182
|
+
|
|
183
|
+
@file = new_file.call(path, format, '*') unless new_file.nil?
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# ========================================================================= #
|
|
187
|
+
# === find_file
|
|
188
|
+
# ========================================================================= #
|
|
189
|
+
def find_file(path, format, layer)
|
|
190
|
+
possible_paths = [
|
|
191
|
+
Proc.new { |inner_path, inner_format, _inner_layer|
|
|
192
|
+
"#{inner_path}.#{inner_format}"
|
|
193
|
+
},
|
|
194
|
+
Proc.new { |inner_path, inner_format, inner_layer|
|
|
195
|
+
"#{inner_path}-#{inner_layer}.#{format}"
|
|
196
|
+
},
|
|
197
|
+
Proc.new { |inner_path, inner_format, inner_layer|
|
|
198
|
+
"#{inner_path}.#{inner_format}.#{inner_layer}"
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
possible_paths.find { |possible_path|
|
|
202
|
+
File.exist?(possible_path.call(path, format, layer))
|
|
203
|
+
}
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# ========================================================================= #
|
|
207
|
+
# === convert (convert tag)
|
|
208
|
+
#
|
|
209
|
+
# Runs ImageMagick's 'convert'.
|
|
210
|
+
#
|
|
211
|
+
# The second argument to this method has to be a Hash, if it is given.
|
|
212
|
+
#
|
|
213
|
+
# See http://www.imagemagick.org/script/convert.php
|
|
214
|
+
# ========================================================================= #
|
|
215
|
+
def convert(output, i = {})
|
|
216
|
+
tokens = ['convert']
|
|
217
|
+
tokens << expand_arguments_to_key_value_pairs(i) if i
|
|
218
|
+
tokens << " '#{@file}#{"[#{i[:layer].to_s}]" if i.has_key?(:layer)}'"
|
|
219
|
+
tokens << " -annotate #{i[:annotate].to_s}" if i.has_key?(:annotate)
|
|
220
|
+
tokens << " #{output}"
|
|
221
|
+
tokens = convert_to_command(tokens)
|
|
222
|
+
success = run_command(tokens)[1]
|
|
223
|
+
success
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# ========================================================================= #
|
|
227
|
+
# === convert_to_command
|
|
228
|
+
#
|
|
229
|
+
# This method adds a proper prefix, which is defined in the file
|
|
230
|
+
# gm_support.rb. Then it joins the commands of the Array at hand.
|
|
231
|
+
# ========================================================================= #
|
|
232
|
+
def convert_to_command(tokens)
|
|
233
|
+
# ======================================================================= #
|
|
234
|
+
# Pass into the method prefix() next.
|
|
235
|
+
# ======================================================================= #
|
|
236
|
+
tokens[0] = prefix(tokens.first) if respond_to? :prefix
|
|
237
|
+
tokens.flatten.join
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# ========================================================================= #
|
|
241
|
+
# === expand_arguments_to_key_value_pairs
|
|
242
|
+
#
|
|
243
|
+
# Convert the entries into a format that ImageMagick understands.
|
|
244
|
+
# ========================================================================= #
|
|
245
|
+
def expand_arguments_to_key_value_pairs(i)
|
|
246
|
+
special_arguments = [ :layer, :annotate ]
|
|
247
|
+
# ======================================================================= #
|
|
248
|
+
# First, reject keys that are not :layer or :annotate.
|
|
249
|
+
# ======================================================================= #
|
|
250
|
+
i.reject {|key, _value| special_arguments.include?(key) }.map {|key, value|
|
|
251
|
+
" -#{key} '#{value}'"
|
|
252
|
+
}
|
|
253
|
+
end; alias convert_arguments expand_arguments_to_key_value_pairs # === convert_arguments
|
|
254
|
+
|
|
255
|
+
# ========================================================================= #
|
|
256
|
+
# === run_command
|
|
257
|
+
#
|
|
258
|
+
# Use IO.popen to run the passed command at hand.
|
|
259
|
+
#
|
|
260
|
+
# The method returns an Array, holding the output, and the success
|
|
261
|
+
# status.
|
|
262
|
+
# ========================================================================= #
|
|
263
|
+
def run_command(i)
|
|
264
|
+
i = i.to_s
|
|
265
|
+
if @display_sys_command
|
|
266
|
+
# ===================================================================== #
|
|
267
|
+
# Show the command if the ivar above is true.
|
|
268
|
+
# ===================================================================== #
|
|
269
|
+
e i
|
|
270
|
+
end
|
|
271
|
+
output = IO.popen(i) {|dataset| dataset.read }
|
|
272
|
+
success = $?.exitstatus == 0 ? true : false
|
|
273
|
+
[output, success]
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# =========================================================================== #
|
|
279
|
+
# === ImageParadise.identify
|
|
280
|
+
# =========================================================================== #
|
|
281
|
+
def self.identify(this_image, hash_arguments = {})
|
|
282
|
+
ImageParadise::ImageManipulations.new(this_image).identify(hash_arguments)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# =========================================================================== #
|
|
286
|
+
# === ImageParadise.convert
|
|
287
|
+
# =========================================================================== #
|
|
288
|
+
def self.convert(this_image, hash_arguments = {})
|
|
289
|
+
ImageParadise::ImageManipulations.new(this_image).convert(hash_arguments)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
# =========================================================================== #
|
|
293
|
+
# === ImageParadise.dimensions
|
|
294
|
+
# =========================================================================== #
|
|
295
|
+
def self.dimensions(this_image, hash_arguments = {})
|
|
296
|
+
ImageParadise::ImageManipulations.new(this_image).dimensions(hash_arguments)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# =========================================================================== #
|
|
300
|
+
# === ImageParadise.montage
|
|
301
|
+
# =========================================================================== #
|
|
302
|
+
def self.montage(this_image, hash_arguments = {})
|
|
303
|
+
ImageParadise::ImageManipulations.new(this_image).montage(hash_arguments)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# =========================================================================== #
|
|
307
|
+
# === ImageParadise.do_manipulate
|
|
308
|
+
# =========================================================================== #
|
|
309
|
+
def self.do_manipulate(this_image, hash_arguments = {})
|
|
310
|
+
ImageParadise::ImageManipulations.new(this_image).do_manipulate(hash_arguments)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# =========================================================================== #
|
|
314
|
+
# === ImageParadise.shrink
|
|
315
|
+
# =========================================================================== #
|
|
316
|
+
def self.shrink(this_image, hash_arguments = {})
|
|
317
|
+
ImageParadise::ImageManipulations.new(this_image).shrink(hash_arguments)
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === ImageParadise::ImageParadise
|
|
6
|
+
#
|
|
7
|
+
# This project can be used to do fancy image manipulations from the
|
|
8
|
+
# commandline, including the de-novo creation of new images.
|
|
9
|
+
#
|
|
10
|
+
# Usage example:
|
|
11
|
+
# ImageParadise::ImageParadise.new
|
|
12
|
+
# =========================================================================== #
|
|
13
|
+
# require 'image_paradise'
|
|
14
|
+
# =========================================================================== #
|
|
15
|
+
require 'image_paradise/requires/common_base_requires.rb'
|
|
16
|
+
require 'image_paradise/toplevel_methods/esystem.rb'
|
|
17
|
+
require 'image_paradise/toplevel_methods/crop.rb'
|
|
18
|
+
require 'image_paradise/toplevel_methods/png_to_svg.rb'
|
|
19
|
+
require 'image_paradise/constants.rb'
|
|
20
|
+
require 'image_paradise/identify.rb'
|
|
21
|
+
require 'image_paradise/create_animated_gif.rb'
|
|
22
|
+
require 'image_paradise/graphs.rb'
|
|
23
|
+
require 'image_paradise/confree_generator/class.rb'
|
|
24
|
+
require 'image_paradise/optimizer.rb'
|
|
25
|
+
|
|
26
|
+
module ImageParadise
|
|
27
|
+
|
|
28
|
+
class ImageParadise # === ImageParadise::ImageParadise
|
|
29
|
+
|
|
30
|
+
# ========================================================================= #
|
|
31
|
+
# === initialize
|
|
32
|
+
#
|
|
33
|
+
# First argument is the filename that we wish to use.
|
|
34
|
+
# ========================================================================= #
|
|
35
|
+
def initialize(
|
|
36
|
+
i = nil,
|
|
37
|
+
run_already = true
|
|
38
|
+
)
|
|
39
|
+
reset
|
|
40
|
+
set_filename(i)
|
|
41
|
+
if run_already.to_s.include? 'dont'
|
|
42
|
+
run_already = false
|
|
43
|
+
end
|
|
44
|
+
run if run_already
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# ========================================================================= #
|
|
48
|
+
# === reset (reset tag)
|
|
49
|
+
# ========================================================================= #
|
|
50
|
+
def reset
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# ========================================================================= #
|
|
54
|
+
# === set_filename
|
|
55
|
+
#
|
|
56
|
+
# This will be the input filename.
|
|
57
|
+
# ========================================================================= #
|
|
58
|
+
def set_filename(i = '')
|
|
59
|
+
i = i.first if i.is_a? Array
|
|
60
|
+
i = i.to_s.dup if i
|
|
61
|
+
@filename = i
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# ========================================================================= #
|
|
65
|
+
# === filename?
|
|
66
|
+
# ========================================================================= #
|
|
67
|
+
def filename?
|
|
68
|
+
@filename
|
|
69
|
+
end; alias input? filename? # === input?
|
|
70
|
+
|
|
71
|
+
# ========================================================================= #
|
|
72
|
+
# === ImageParadise.font_tiled
|
|
73
|
+
# ========================================================================= #
|
|
74
|
+
def self.font_tiled(i = DEFAULT_TEXT)
|
|
75
|
+
i = DEFAULT_TEXT if i.nil?
|
|
76
|
+
width_and_height = '500x250'
|
|
77
|
+
_ = CONVERT+" -size "+width_and_height+" xc:lightblue -font "+
|
|
78
|
+
DEFAULT_FONT+" -pointsize 68
|
|
79
|
+
-tile pattern:checkerboard -annotate +28+68 '"+i+"'
|
|
80
|
+
font_tile.jpg"
|
|
81
|
+
esys _
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# ========================================================================= #
|
|
85
|
+
# === ImageParadise.esys
|
|
86
|
+
# ========================================================================= #
|
|
87
|
+
def self.esys(i)
|
|
88
|
+
i.delete!(N)
|
|
89
|
+
esystem(i)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# ========================================================================= #
|
|
93
|
+
# === esys
|
|
94
|
+
# ========================================================================= #
|
|
95
|
+
def esys(i)
|
|
96
|
+
ImageParadise.esys(i)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# ========================================================================= #
|
|
100
|
+
# === colourize
|
|
101
|
+
#
|
|
102
|
+
# Input should be R,G,B values.
|
|
103
|
+
# ========================================================================= #
|
|
104
|
+
def colourize(rgb_values = '2,15,75')
|
|
105
|
+
case rgb_values
|
|
106
|
+
when :randomize, :random
|
|
107
|
+
rgb_values = (rand(255)+1).to_s+','+(rand(255)+1).to_s+','+(rand(255)+1).to_s
|
|
108
|
+
end
|
|
109
|
+
_ = CONVERT+' -colorize '+rgb_values+' '+input?+' '+output?
|
|
110
|
+
ImageParadise.esys _
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# ========================================================================= #
|
|
114
|
+
# === output
|
|
115
|
+
# ========================================================================= #
|
|
116
|
+
def output?
|
|
117
|
+
'output.png'
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# ========================================================================= #
|
|
121
|
+
# === ImageParadise.resize
|
|
122
|
+
#
|
|
123
|
+
# This is equivalent to:
|
|
124
|
+
# convert terminal.gif -resize 64x64 resize_terminal.gif
|
|
125
|
+
# ========================================================================= #
|
|
126
|
+
def self.resize(resize_how = '-resize 64x64')
|
|
127
|
+
_ = CONVERT+' '+resize_how+' '+input_output?
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# ========================================================================= #
|
|
131
|
+
# === input_output?
|
|
132
|
+
# ========================================================================= #
|
|
133
|
+
def input_output?
|
|
134
|
+
input?+' '+output?
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# ========================================================================= #
|
|
138
|
+
# === run
|
|
139
|
+
# ========================================================================= #
|
|
140
|
+
def run # (run tag)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
end; end
|
|
144
|
+
|
|
145
|
+
if __FILE__ == $PROGRAM_NAME
|
|
146
|
+
# _ = ImageParadise.new(ARGV, :dont_run_yet)
|
|
147
|
+
# _.run
|
|
148
|
+
ImageParadise::ImageParadise.crop('rose.jpg')
|
|
149
|
+
end # rimage
|
|
150
|
+
# require 'image_paradise'; ImageParadise.new('foo.jpg').colourize :random
|