image_paradise 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
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,126 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ImageParadise::GUI::Gtk::ControlPanel
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'image_paradise/gui/gtk/control_panel.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'gtk_paradise/requires/require_the_base_module.rb'
|
10
|
+
|
11
|
+
module ImageParadise
|
12
|
+
|
13
|
+
module GUI
|
14
|
+
|
15
|
+
module Gtk
|
16
|
+
|
17
|
+
class ControlPanel < ::Gtk::VBox # === ImageParadise::GUI::Gtk::ControlPanel
|
18
|
+
|
19
|
+
require 'image_paradise/toplevel_methods/merge_these_images.rb'
|
20
|
+
|
21
|
+
include ::Gtk::BaseModule
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === WIDTH
|
25
|
+
# ========================================================================= #
|
26
|
+
WIDTH = 1020
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === HEIGHT
|
30
|
+
# ========================================================================= #
|
31
|
+
HEIGHT = 420
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === initialize
|
35
|
+
# ========================================================================= #
|
36
|
+
def initialize
|
37
|
+
super()
|
38
|
+
reset
|
39
|
+
connect_skeleton
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === reset
|
44
|
+
# ========================================================================= #
|
45
|
+
def reset
|
46
|
+
increase_font_size
|
47
|
+
set_size_request(
|
48
|
+
WIDTH,
|
49
|
+
HEIGHT
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# ========================================================================= #
|
54
|
+
# === connect_skeleton
|
55
|
+
# ========================================================================= #
|
56
|
+
def connect_skeleton
|
57
|
+
try_to_change_directory
|
58
|
+
@gtk_entry_working_directory = gtk_entry(return_pwd)
|
59
|
+
hbox1 = gtk_hbox(
|
60
|
+
bold_label: 'Working directory is:',
|
61
|
+
entry: @gtk_entry_working_directory
|
62
|
+
)
|
63
|
+
pack_start(
|
64
|
+
hbox1, false, false, 0
|
65
|
+
)
|
66
|
+
|
67
|
+
@gtk_entry_for_merging_images = gtk_entry
|
68
|
+
hbox2 = gtk_hbox(
|
69
|
+
bold_label: 'Merge these images together:',
|
70
|
+
entry: @gtk_entry_for_merging_images
|
71
|
+
)
|
72
|
+
pack_start(
|
73
|
+
hbox2, false, false, 0
|
74
|
+
)
|
75
|
+
@button_merge_these_images = gtk_button('_Merge these images together.')
|
76
|
+
@button_merge_these_images.signal_connect(:clicked) {
|
77
|
+
do_merge_these_images
|
78
|
+
}
|
79
|
+
pack_start(
|
80
|
+
@button_merge_these_images, false, false
|
81
|
+
)
|
82
|
+
@gtk_entry_this_image_was_merged = gtk_entry
|
83
|
+
pack_start(
|
84
|
+
@gtk_entry_this_image_was_merged, false, false
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
# ========================================================================= #
|
89
|
+
# === try_to_change_directory
|
90
|
+
# ========================================================================= #
|
91
|
+
def try_to_change_directory
|
92
|
+
cd '/Depot/j' if File.directory? '/Depot/j'
|
93
|
+
end
|
94
|
+
|
95
|
+
# ========================================================================= #
|
96
|
+
# === do_merge_these_images
|
97
|
+
# ========================================================================= #
|
98
|
+
def do_merge_these_images
|
99
|
+
cd @gtk_entry_working_directory.text
|
100
|
+
_ = @gtk_entry_for_merging_images.text
|
101
|
+
if _.include? ' '
|
102
|
+
_ = _.split(' ')
|
103
|
+
end
|
104
|
+
result = ::ImageParadise.merge_these_images(_)
|
105
|
+
@gtk_entry_this_image_was_merged.set_text(result)
|
106
|
+
end
|
107
|
+
|
108
|
+
end; end; end
|
109
|
+
|
110
|
+
# =========================================================================== #
|
111
|
+
# === ImageParadise.gtk_widget
|
112
|
+
# =========================================================================== #
|
113
|
+
def self.gtk_widget
|
114
|
+
::ImageParadise::GUI::Gtk::ControlPanel.new
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
if __FILE__ == $PROGRAM_NAME
|
120
|
+
require 'gtk_paradise/run.rb'
|
121
|
+
r = Gtk.run
|
122
|
+
r.title = 'Control Panel for the ImageParadise project'
|
123
|
+
x = ImageParadise::GUI::Gtk::ControlPanel.new
|
124
|
+
r << x
|
125
|
+
r.top_left_then_run
|
126
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ImageParadise::Identify
|
6
|
+
#
|
7
|
+
# The purpose of this class is to simply gather all information that
|
8
|
+
# we can obtain by ImageMagick's identify command.
|
9
|
+
#
|
10
|
+
# Currently, we use the plain "identify" binary. We could also use
|
11
|
+
# RMagick, but for now we shall not do so.
|
12
|
+
# =========================================================================== #
|
13
|
+
# require 'image_paradise/identify.rb'
|
14
|
+
# =========================================================================== #
|
15
|
+
require 'image_paradise/base/base.rb'
|
16
|
+
|
17
|
+
module ImageParadise
|
18
|
+
|
19
|
+
class Identify < ::ImageParadise::Base
|
20
|
+
|
21
|
+
# ========================================================================= #
|
22
|
+
# === CMD_TO_RUN
|
23
|
+
# ========================================================================= #
|
24
|
+
CMD_TO_RUN = 'identify -verbose' # Could also be "identify".
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === initialize
|
28
|
+
# ========================================================================= #
|
29
|
+
def initialize(
|
30
|
+
this_image_file = 'test.png',
|
31
|
+
run_already = true
|
32
|
+
)
|
33
|
+
reset
|
34
|
+
set_use_this_image_file(this_image_file)
|
35
|
+
run if run_already
|
36
|
+
end
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === set_use_this_image_file
|
40
|
+
# ========================================================================= #
|
41
|
+
def set_use_this_image_file(i)
|
42
|
+
if i.is_a? Array
|
43
|
+
i = i.first
|
44
|
+
end
|
45
|
+
@use_this_image_file = i
|
46
|
+
end
|
47
|
+
|
48
|
+
# ========================================================================= #
|
49
|
+
# === reset
|
50
|
+
# ========================================================================= #
|
51
|
+
def reset
|
52
|
+
# ======================================================================= #
|
53
|
+
# === @result
|
54
|
+
# ======================================================================= #
|
55
|
+
@result = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# ========================================================================= #
|
59
|
+
# === report_result
|
60
|
+
# ========================================================================= #
|
61
|
+
def report_result
|
62
|
+
e @result
|
63
|
+
end
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === report_everything
|
67
|
+
# ========================================================================= #
|
68
|
+
def report_everything
|
69
|
+
report_internal_attributes
|
70
|
+
report_result
|
71
|
+
end
|
72
|
+
|
73
|
+
# ========================================================================= #
|
74
|
+
# === report
|
75
|
+
# ========================================================================= #
|
76
|
+
def report
|
77
|
+
e
|
78
|
+
report_internal_attributes {{ padding: 2 }}
|
79
|
+
e
|
80
|
+
end
|
81
|
+
|
82
|
+
# ========================================================================= #
|
83
|
+
# === report_internal_attributes
|
84
|
+
# ========================================================================= #
|
85
|
+
def report_internal_attributes
|
86
|
+
padding_to_use = ''.dup
|
87
|
+
if block_given?
|
88
|
+
yielded = yield
|
89
|
+
if yielded.is_a? Hash
|
90
|
+
# =================================================================== #
|
91
|
+
# === :padding
|
92
|
+
# =================================================================== #
|
93
|
+
if yielded.has_key? :padding
|
94
|
+
padding_to_use << ' ' * yielded[:padding]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
n_just = 18
|
99
|
+
e steelblue(padding_to_use+'Mime type: '.ljust(n_just))+
|
100
|
+
mediumseagreen(@mime_type)
|
101
|
+
e steelblue(padding_to_use+'Width: '.ljust(n_just))+
|
102
|
+
mediumseagreen(@width)
|
103
|
+
e steelblue(padding_to_use+'Height: '.ljust(n_just))+
|
104
|
+
mediumseagreen(@height)
|
105
|
+
e steelblue(padding_to_use+'Background color: '.ljust(n_just))+
|
106
|
+
mediumseagreen(@background_color)
|
107
|
+
e steelblue(padding_to_use+'Resolution: '.ljust(n_just))+
|
108
|
+
mediumseagreen(@resolution)
|
109
|
+
e steelblue(padding_to_use+'Quality: '.ljust(n_just))+
|
110
|
+
mediumseagreen(@quality)
|
111
|
+
end
|
112
|
+
|
113
|
+
# ========================================================================= #
|
114
|
+
# === analyze_result
|
115
|
+
# ========================================================================= #
|
116
|
+
def analyze_result
|
117
|
+
_ = @use_this_image_file
|
118
|
+
if _ and File.exist?(_)
|
119
|
+
@result = `#{CMD_TO_RUN} #{_}`
|
120
|
+
else
|
121
|
+
e 'No file could be found. Please provide a valid '\
|
122
|
+
'argument to this class.'
|
123
|
+
end
|
124
|
+
if @result
|
125
|
+
@mime_type = @result.scan(/Mime type:(.+)$/).flatten.first.strip
|
126
|
+
@width, @height = @result.scan(/Geometry:(.+)$/).flatten.first.split('x').map(&:strip)
|
127
|
+
@resolution = @result.scan(/Resolution:(.+)$/).flatten.first.strip
|
128
|
+
@background_color = @result.scan(/Background color:(.+)$/).flatten.first.strip
|
129
|
+
@quality = @result.scan(/Quality:(.+)$/).flatten.first.strip
|
130
|
+
report
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# ========================================================================= #
|
135
|
+
# === run (run tag)
|
136
|
+
# ========================================================================= #
|
137
|
+
def run
|
138
|
+
analyze_result
|
139
|
+
end
|
140
|
+
|
141
|
+
end; end
|
142
|
+
|
143
|
+
if __FILE__ == $PROGRAM_NAME
|
144
|
+
ImageParadise::Identify.new(ARGV)
|
145
|
+
end # ruby_identify
|
@@ -0,0 +1,231 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ImageParadise::ImageBorder
|
6
|
+
#
|
7
|
+
# This class will create a border around a given image.
|
8
|
+
#
|
9
|
+
# The syntax should be:
|
10
|
+
#
|
11
|
+
# image_border foobar.png --colour red --dimension 50x20
|
12
|
+
#
|
13
|
+
# Usage example:
|
14
|
+
# ImageParadise::ImageBorder.new
|
15
|
+
# =========================================================================== #
|
16
|
+
# require 'image_paradise/image_border.rb'
|
17
|
+
# =========================================================================== #
|
18
|
+
require 'image_paradise/base/base.rb'
|
19
|
+
|
20
|
+
module ImageParadise
|
21
|
+
|
22
|
+
class ImageBorder < ::ImageParadise::Base # === ImageParadise::ImageBorder.new
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === DELETE_OUTPUT_FILE_IF_IT_EXISTS
|
26
|
+
# ========================================================================= #
|
27
|
+
DELETE_OUTPUT_FILE_IF_IT_EXISTS = true
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === initialize
|
31
|
+
# ========================================================================= #
|
32
|
+
def initialize(
|
33
|
+
i = nil,
|
34
|
+
run_already = true
|
35
|
+
)
|
36
|
+
reset
|
37
|
+
set_this_image_file(i)
|
38
|
+
run if run_already
|
39
|
+
end
|
40
|
+
|
41
|
+
# ========================================================================= #
|
42
|
+
# === reset (reset tag)
|
43
|
+
# ========================================================================= #
|
44
|
+
def reset
|
45
|
+
super()
|
46
|
+
set_border_colour :random # Initialize as default border-colour.
|
47
|
+
@dimension = '10x10'
|
48
|
+
end
|
49
|
+
|
50
|
+
# ========================================================================= #
|
51
|
+
# === colour?
|
52
|
+
# ========================================================================= #
|
53
|
+
def colour?
|
54
|
+
@border_colour
|
55
|
+
end
|
56
|
+
|
57
|
+
# ========================================================================= #
|
58
|
+
# === set_this_image_file
|
59
|
+
# ========================================================================= #
|
60
|
+
def set_this_image_file(i = '')
|
61
|
+
i = i.join(' ').strip if i.is_a? Array
|
62
|
+
i.squeeze!(' ')
|
63
|
+
i = parse_this_input(i)
|
64
|
+
i.strip!
|
65
|
+
menu(i)
|
66
|
+
@this_image_file = i
|
67
|
+
end
|
68
|
+
|
69
|
+
# ========================================================================= #
|
70
|
+
# === show_help (help tag)
|
71
|
+
# ========================================================================= #
|
72
|
+
def show_help
|
73
|
+
help_string = <<-EOF
|
74
|
+
|
75
|
+
These options are available:
|
76
|
+
|
77
|
+
image_border foobar.png --colour RANDOM --dimension 50x25
|
78
|
+
|
79
|
+
EOF
|
80
|
+
e help_string
|
81
|
+
end
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === menu (menu tag)
|
85
|
+
# ========================================================================= #
|
86
|
+
def menu(i)
|
87
|
+
case i # case tag
|
88
|
+
# ======================================================================= #
|
89
|
+
# === image_border --help
|
90
|
+
# ======================================================================= #
|
91
|
+
when /--help/
|
92
|
+
show_help
|
93
|
+
exit
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# ========================================================================= #
|
98
|
+
# === parse_this_input
|
99
|
+
#
|
100
|
+
# This method will parse the commandline options.
|
101
|
+
# ========================================================================= #
|
102
|
+
def parse_this_input(i)
|
103
|
+
if i =~ /(--colour (\S{1,25}))/
|
104
|
+
set_colour($2.to_s.dup)
|
105
|
+
i.sub!(/#{$1.to_s}/,'')
|
106
|
+
end
|
107
|
+
if i =~ /(--dimension (\S{1,25}))/
|
108
|
+
set_dimension($2.to_s.dup)
|
109
|
+
i.sub!(/#{$1.to_s}/,'')
|
110
|
+
end
|
111
|
+
return i
|
112
|
+
end
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === set_dimension
|
116
|
+
# ========================================================================= #
|
117
|
+
def set_dimension(i)
|
118
|
+
@dimension = i
|
119
|
+
end
|
120
|
+
|
121
|
+
# ========================================================================= #
|
122
|
+
# === set_border_colour
|
123
|
+
# ========================================================================= #
|
124
|
+
def set_border_colour(i = 'SkyBlue')
|
125
|
+
case i.to_s
|
126
|
+
when 'default'
|
127
|
+
i = 'black'
|
128
|
+
when 'RANDOM','random'
|
129
|
+
require 'colours' unless Object.const_defined? :Colours
|
130
|
+
i = Colours.random_html_colour
|
131
|
+
end
|
132
|
+
@border_colour = i
|
133
|
+
end; alias set_colour set_border_colour # === set_colour
|
134
|
+
|
135
|
+
# ========================================================================= #
|
136
|
+
# === this_image_file?
|
137
|
+
# ========================================================================= #
|
138
|
+
def this_image_file?
|
139
|
+
@this_image_file
|
140
|
+
end; alias input? this_image_file? # === input?
|
141
|
+
alias input_file? this_image_file? # === input_file?
|
142
|
+
|
143
|
+
# ========================================================================= #
|
144
|
+
# === name_of_the_output_file?
|
145
|
+
# ========================================================================= #
|
146
|
+
def name_of_the_output_file?
|
147
|
+
'OUTPUT_'+input_file?.sub(/\.png$/,'').sub(/\.jpg$/,'')+'.png'
|
148
|
+
end; alias output_file? name_of_the_output_file? # === output_file?
|
149
|
+
|
150
|
+
# ========================================================================= #
|
151
|
+
# === determine_name_of_the_output_file
|
152
|
+
#
|
153
|
+
# Use this method to determine the name of the output file that will
|
154
|
+
# be created de-novo.
|
155
|
+
# ========================================================================= #
|
156
|
+
def determine_name_of_the_output_file
|
157
|
+
_ = name_of_the_output_file?
|
158
|
+
if File.exist?(_) and !DELETE_OUTPUT_FILE_IF_IT_EXISTS
|
159
|
+
# ===================================================================== #
|
160
|
+
# In this case use a randomized name.
|
161
|
+
# ===================================================================== #
|
162
|
+
sample = ''
|
163
|
+
20.times { sample << ALPHABET.sample }
|
164
|
+
_ = 'OUTPUT_'+sample+input_file?.sub(/\.png$/,'').sub(/\.jpg$/,'')+'.png'
|
165
|
+
end
|
166
|
+
return _
|
167
|
+
end
|
168
|
+
|
169
|
+
# ========================================================================= #
|
170
|
+
# === cmd?
|
171
|
+
# ========================================================================= #
|
172
|
+
def cmd?
|
173
|
+
@cmd
|
174
|
+
end
|
175
|
+
|
176
|
+
# ========================================================================= #
|
177
|
+
# === run_main_command
|
178
|
+
# ========================================================================= #
|
179
|
+
def run_main_command
|
180
|
+
_ = cmd?
|
181
|
+
if DELETE_OUTPUT_FILE_IF_IT_EXISTS and output_file_exists?
|
182
|
+
File.delete output_file?
|
183
|
+
end
|
184
|
+
e _
|
185
|
+
system _
|
186
|
+
end
|
187
|
+
|
188
|
+
# ========================================================================= #
|
189
|
+
# === output_file_exists?
|
190
|
+
# ========================================================================= #
|
191
|
+
def output_file_exists?
|
192
|
+
File.exist? name_of_the_output_file?
|
193
|
+
end
|
194
|
+
|
195
|
+
# ========================================================================= #
|
196
|
+
# === assemble_main_command
|
197
|
+
# ========================================================================= #
|
198
|
+
def assemble_main_command
|
199
|
+
@cmd = CONVERT+' '
|
200
|
+
@cmd << input_file?+' '
|
201
|
+
@cmd << '-bordercolor '+colour?+' '
|
202
|
+
@cmd << '-border '+@dimension+' '
|
203
|
+
name_of_the_output_file = determine_name_of_the_output_file
|
204
|
+
@cmd << name_of_the_output_file
|
205
|
+
end
|
206
|
+
|
207
|
+
# ========================================================================= #
|
208
|
+
# === run (run tag)
|
209
|
+
# ========================================================================= #
|
210
|
+
def run
|
211
|
+
_ = input_file?
|
212
|
+
if File.exist? _
|
213
|
+
assemble_main_command
|
214
|
+
run_main_command
|
215
|
+
else
|
216
|
+
opn; e 'No file called '+sfile(_)+' exists.'
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# ========================================================================= #
|
221
|
+
# === ImageParadise::ImageBorder[]
|
222
|
+
# ========================================================================= #
|
223
|
+
def self.[](i = '')
|
224
|
+
new(i)
|
225
|
+
end
|
226
|
+
|
227
|
+
end; end
|
228
|
+
|
229
|
+
if __FILE__ == $PROGRAM_NAME
|
230
|
+
ImageParadise::ImageBorder.new(ARGV)
|
231
|
+
end # image_border foobar.png --colour RANDOM --dimension 50x25
|