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,78 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === ImageParadise::InsertButton
|
|
6
|
+
#
|
|
7
|
+
# require 'image_paradise/confree_generator/gui/insert_button.rb'
|
|
8
|
+
# =========================================================================== #
|
|
9
|
+
# This button is used to insert a line at the current iter.
|
|
10
|
+
# InsertButton.new
|
|
11
|
+
# =========================================================================== #
|
|
12
|
+
module ImageParadise
|
|
13
|
+
|
|
14
|
+
class InsertButton < Gtk::Button
|
|
15
|
+
|
|
16
|
+
include Gtk::Colours
|
|
17
|
+
|
|
18
|
+
# ========================================================================= #
|
|
19
|
+
# === initialize
|
|
20
|
+
# ========================================================================= #
|
|
21
|
+
def initialize(mode, master_widget)
|
|
22
|
+
super('Insert ' << mode.to_s.upcase)
|
|
23
|
+
set_mode(mode)
|
|
24
|
+
@master_widget = master_widget
|
|
25
|
+
self.modify_bg( Gtk::StateType::NORMAL, CADETBLUE )
|
|
26
|
+
self.modify_bg( Gtk::StateType::ACTIVE, BROWN )
|
|
27
|
+
self.modify_bg( Gtk::StateType::PRELIGHT, BISQUE )
|
|
28
|
+
self.set_size_request(66, 28)
|
|
29
|
+
self.set_border_width(0)
|
|
30
|
+
self.signal_connect(:clicked) { |widget, event| check_args(@mode) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# ========================================================================= #
|
|
34
|
+
# === set_mode
|
|
35
|
+
# ========================================================================= #
|
|
36
|
+
def set_mode(i)
|
|
37
|
+
@mode = i
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# ========================================================================= #
|
|
41
|
+
# === check_args
|
|
42
|
+
#
|
|
43
|
+
# Here we check for the different insert buttons.
|
|
44
|
+
# ========================================================================= #
|
|
45
|
+
def check_args(which_mode)
|
|
46
|
+
_ = @master_widget.source_buffer
|
|
47
|
+
case which_mode
|
|
48
|
+
when :comment
|
|
49
|
+
_.insert_at_cursor(
|
|
50
|
+
'# ===================================== #'+N)
|
|
51
|
+
_.insert_at_cursor(
|
|
52
|
+
'# '+N)
|
|
53
|
+
_.insert_at_cursor(
|
|
54
|
+
'# ===================================== #'+N)
|
|
55
|
+
when :background
|
|
56
|
+
_.insert_at_cursor('background { b -0.95 sat 1 hue 180 }')
|
|
57
|
+
when :square
|
|
58
|
+
_.insert_at_cursor('SQUARE {}')
|
|
59
|
+
when :triangle
|
|
60
|
+
_.insert_at_cursor('TRIANGLE {}')
|
|
61
|
+
when :line
|
|
62
|
+
_.insert_at_cursor('LINE {}')
|
|
63
|
+
when :rect
|
|
64
|
+
_.insert_at_cursor('RECT {}')
|
|
65
|
+
when :circle
|
|
66
|
+
_.insert_at_cursor('CIRCLE {}')
|
|
67
|
+
when :hue
|
|
68
|
+
_.insert_at_cursor(' hue 10 ')
|
|
69
|
+
when :sat
|
|
70
|
+
_.insert_at_cursor(' sat 0.995 ')
|
|
71
|
+
when :b
|
|
72
|
+
_.insert_at_cursor(' b 0.995 ')
|
|
73
|
+
when :n
|
|
74
|
+
_.insert_at_cursor("\n")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end; end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'image_paradise/confree_generator/reset.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ImageParadise
|
|
8
|
+
|
|
9
|
+
class ConfreeGenerator < ::ImageParadise::Base # === ImageParadise::ConfreeGenerator
|
|
10
|
+
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
# === reset (reset tag)
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def reset
|
|
15
|
+
# ======================================================================= #
|
|
16
|
+
# === @try_to_open_the_generated_image_in_the_browser
|
|
17
|
+
# ======================================================================= #
|
|
18
|
+
@try_to_open_the_generated_image_in_the_browser =
|
|
19
|
+
TRY_TO_OPEN_THE_GENERATED_IMAGE_IN_THE_BROWSER
|
|
20
|
+
# ======================================================================= #
|
|
21
|
+
# === @create_image
|
|
22
|
+
# ======================================================================= #
|
|
23
|
+
@create_image = true
|
|
24
|
+
# ======================================================================= #
|
|
25
|
+
# The variable @html_file tells us where to store html stuff into.
|
|
26
|
+
#
|
|
27
|
+
# By default it will point at:
|
|
28
|
+
#
|
|
29
|
+
# /Depot/Images/Confree_Images.html
|
|
30
|
+
#
|
|
31
|
+
# ======================================================================= #
|
|
32
|
+
@html_file = "#{TEMP_IMAGES}Confree_Images.html"
|
|
33
|
+
# ======================================================================= #
|
|
34
|
+
# === @file_listing
|
|
35
|
+
# ======================================================================= #
|
|
36
|
+
@file_listing = nil # will contain files in my IMG/CFDG dir
|
|
37
|
+
@batch_mode = false
|
|
38
|
+
# ======================================================================= #
|
|
39
|
+
# === @n_confree_files
|
|
40
|
+
# ======================================================================= #
|
|
41
|
+
@n_confree_files = 0
|
|
42
|
+
set_location_of_output_file
|
|
43
|
+
set_width_then_height(
|
|
44
|
+
DEFAULT_WIDTH,
|
|
45
|
+
DEFAULT_HEIGHT
|
|
46
|
+
)
|
|
47
|
+
# ======================================================================= #
|
|
48
|
+
# === @create_html_gallery
|
|
49
|
+
# ======================================================================= #
|
|
50
|
+
@create_html_gallery = CREATE_HTML_GALLERY # If true, we create a html gallery.
|
|
51
|
+
# ======================================================================= #
|
|
52
|
+
# The next flag can be true or false.
|
|
53
|
+
#
|
|
54
|
+
# By default it should be true. If it is true, we will generate the
|
|
55
|
+
# image in question. Sometimes though, we may only want to generate
|
|
56
|
+
# the HTML code - that is why this variable exists.
|
|
57
|
+
# ======================================================================= #
|
|
58
|
+
@generate_the_image = GENERATE_THE_IMAGE
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end; end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === ImageParadise::ConfreeGenerator::Shared
|
|
6
|
+
#
|
|
7
|
+
# Data to be exchanged between the different .rb files in the
|
|
8
|
+
# confree_generator project is bundled into this file here.
|
|
9
|
+
# =========================================================================== #
|
|
10
|
+
# require 'image_paradise/confree_generator/shared/shared.rb'
|
|
11
|
+
# =========================================================================== #
|
|
12
|
+
require 'image_paradise/confree_generator/constants.rb'
|
|
13
|
+
require 'image_paradise/base/base.rb'
|
|
14
|
+
require 'image_paradise/toplevel_methods/file_related_code.rb'
|
|
15
|
+
|
|
16
|
+
module ImageParadise
|
|
17
|
+
|
|
18
|
+
class ConfreeGenerator < ::ImageParadise::Base # === ImageParadise::ConfreeGenerator::Shared
|
|
19
|
+
|
|
20
|
+
module Shared # require 'confree_generator/shared.rb'; include Shared
|
|
21
|
+
|
|
22
|
+
include Colours
|
|
23
|
+
|
|
24
|
+
N = "\n" # Newline.
|
|
25
|
+
|
|
26
|
+
# ========================================================================= #
|
|
27
|
+
# === ARRAY_SKIP_THESE_FILES
|
|
28
|
+
#
|
|
29
|
+
# The following Array lists all .cfdg files which should be be part of
|
|
30
|
+
# what we return with "get_all_cfdg_files".
|
|
31
|
+
#
|
|
32
|
+
# Some .cfdg files that take notoriously long to process can be
|
|
33
|
+
# added to this array.
|
|
34
|
+
# ========================================================================= #
|
|
35
|
+
ARRAY_SKIP_THESE_CFDG_FILES = %w(
|
|
36
|
+
std_cfdg.cfdg
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# ========================================================================= #
|
|
40
|
+
# Height and Width settings. Should not be too large because otherwise
|
|
41
|
+
# the generated image files may be really huge.
|
|
42
|
+
# ========================================================================= #
|
|
43
|
+
|
|
44
|
+
# ========================================================================= #
|
|
45
|
+
# === DEFAULT_HEIGHT
|
|
46
|
+
# ========================================================================= #
|
|
47
|
+
DEFAULT_HEIGHT = '420' # default height for an image
|
|
48
|
+
|
|
49
|
+
# ========================================================================= #
|
|
50
|
+
# === DEFAULT_WIDTH
|
|
51
|
+
# ========================================================================= #
|
|
52
|
+
DEFAULT_WIDTH = '280' # default width for an image
|
|
53
|
+
|
|
54
|
+
# ========================================================================= #
|
|
55
|
+
# === MY_CONFREE_DIR
|
|
56
|
+
#
|
|
57
|
+
# This constants defines the directory where our .cfdg files reside.
|
|
58
|
+
# You can either set an environment variable, called CFDG, or simply
|
|
59
|
+
# hardcode the value. This constant is very important for batch-processing.
|
|
60
|
+
# ========================================================================= #
|
|
61
|
+
if ENV['CFDG']
|
|
62
|
+
MY_CONFREE_DIR = ENV['CFDG'].to_s.dup+'/'
|
|
63
|
+
else
|
|
64
|
+
MY_CONFREE_DIR = '/Users/x/DATA/IMG/CFDG/' # '/tmp/'
|
|
65
|
+
end; DIRECTORY_WITH_CFDG_IMAGES = MY_CONFREE_DIR; CFDG_DIRECTORY = MY_CONFREE_DIR
|
|
66
|
+
|
|
67
|
+
# ========================================================================= #
|
|
68
|
+
# Where our TEMP dir is defined.
|
|
69
|
+
# ========================================================================= #
|
|
70
|
+
if ENV['MY_TEMP']
|
|
71
|
+
TEMP_DIR = ENV['MY_TEMP'].to_s.dup+'/'
|
|
72
|
+
else
|
|
73
|
+
TEMP_DIR = '/Depot/Temp/' # Hardcoded for now.
|
|
74
|
+
end
|
|
75
|
+
TEMP_IMAGES = '/Depot/Images/'
|
|
76
|
+
HTML_FILE_CONFREE_IMAGES = '/Depot/Information/Confree_Images.html'
|
|
77
|
+
YOUR_FAVOURITE_EDITOR = 'bluefish' # Your favourite editor comes here.
|
|
78
|
+
|
|
79
|
+
# ========================================================================= #
|
|
80
|
+
# === get_random_cfdg_file
|
|
81
|
+
#
|
|
82
|
+
# This method will obtain one random .cfdg file.
|
|
83
|
+
# ========================================================================= #
|
|
84
|
+
def get_random_cfdg_file(i = DIRECTORY_WITH_CFDG_IMAGES)
|
|
85
|
+
get_all_cfdg_files(i).sample
|
|
86
|
+
end; alias get_random_cfdg get_random_cfdg_file # === get_random_cfdg
|
|
87
|
+
|
|
88
|
+
# ========================================================================= #
|
|
89
|
+
# === get_all_cfdg_files
|
|
90
|
+
#
|
|
91
|
+
# This method will try to get all .cfdg files, except for
|
|
92
|
+
# all entries we stored in our Array at the top.
|
|
93
|
+
# ========================================================================= #
|
|
94
|
+
def get_all_cfdg_files(
|
|
95
|
+
i = DIRECTORY_WITH_CFDG_IMAGES
|
|
96
|
+
)
|
|
97
|
+
Dir["#{i}*.cfdg"] - ARRAY_SKIP_THESE_CFDG_FILES
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end; end; end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'image_paradise/constants.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ImageParadise
|
|
8
|
+
|
|
9
|
+
require 'image_paradise/project/project.rb'
|
|
10
|
+
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
# === N
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
N = "\n"
|
|
15
|
+
|
|
16
|
+
# ========================================================================= #
|
|
17
|
+
# === ALPHABET
|
|
18
|
+
# ========================================================================= #
|
|
19
|
+
ALPHABET = ('a'..'z').to_a
|
|
20
|
+
|
|
21
|
+
# ========================================================================= #
|
|
22
|
+
# === DEFAULT_CROP_COMMAND_TO_USE
|
|
23
|
+
# ========================================================================= #
|
|
24
|
+
DEFAULT_CROP_COMMAND_TO_USE = '125x125+35+35'
|
|
25
|
+
|
|
26
|
+
# ========================================================================= #
|
|
27
|
+
# === DEFAULT_TEXT
|
|
28
|
+
#
|
|
29
|
+
# This is the default text.
|
|
30
|
+
# ========================================================================= #
|
|
31
|
+
DEFAULT_TEXT = 'Hello World!'
|
|
32
|
+
|
|
33
|
+
# ========================================================================= #
|
|
34
|
+
# === DEFAULT_FONT
|
|
35
|
+
# ========================================================================= #
|
|
36
|
+
DEFAULT_FONT = 'Terminus'
|
|
37
|
+
|
|
38
|
+
# ========================================================================= #
|
|
39
|
+
# === CONVERT
|
|
40
|
+
# ========================================================================= #
|
|
41
|
+
CONVERT = 'convert'
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'image_paradise/constants/image_file_types.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ImageParadise
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === ImageParadise::ARRAY_IMAGE_FILE_TYPES
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
ARRAY_IMAGE_FILE_TYPES = %w(
|
|
13
|
+
.png
|
|
14
|
+
.gif
|
|
15
|
+
.tiff
|
|
16
|
+
.jpg
|
|
17
|
+
.bmp
|
|
18
|
+
.ascii
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
module ImageParadise
|
|
6
|
+
|
|
7
|
+
# ========================================================================= #
|
|
8
|
+
# === INPUT_IMAGES_FOR_THE_CREATION_OF_ANIMATED_GIFS
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
INPUT_IMAGES_FOR_THE_CREATION_OF_ANIMATED_GIFS = '*.gif'
|
|
11
|
+
|
|
12
|
+
# ========================================================================= #
|
|
13
|
+
# === DELAY_FOR_THE_CREATION_OF_ANIMATED_GIFS
|
|
14
|
+
# ========================================================================= #
|
|
15
|
+
DELAY_FOR_THE_CREATION_OF_ANIMATED_GIFS = '100'
|
|
16
|
+
|
|
17
|
+
# ========================================================================= #
|
|
18
|
+
# === ImageParadise.create_animated_gif
|
|
19
|
+
#
|
|
20
|
+
# This method will create an animated gif.
|
|
21
|
+
#
|
|
22
|
+
# The input should be either an Array of input_images, or a string which
|
|
23
|
+
# will be used to create the command.
|
|
24
|
+
#
|
|
25
|
+
# A delay of 100 means 1 second delay.
|
|
26
|
+
# ========================================================================= #
|
|
27
|
+
def self.create_animated_gif(
|
|
28
|
+
input_images = INPUT_IMAGES_FOR_THE_CREATION_OF_ANIMATED_GIFS,
|
|
29
|
+
delay = DELAY_FOR_THE_CREATION_OF_ANIMATED_GIFS
|
|
30
|
+
)
|
|
31
|
+
output_name = 'animated_gif.gif'
|
|
32
|
+
_ = 'convert -delay 100 -loop 0 '+input_images+' '+output_name
|
|
33
|
+
esystem _
|
|
34
|
+
e 'Finished creating `'+sfile(output_name)+'`.' if File.exist? output_name
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# ========================================================================= #
|
|
38
|
+
# === create_animated_gif
|
|
39
|
+
# ========================================================================= #
|
|
40
|
+
def create_animated_gif(
|
|
41
|
+
input_images = INPUT_IMAGES_FOR_THE_CREATION_OF_ANIMATED_GIFS,
|
|
42
|
+
delay = DELAY_FOR_THE_CREATION_OF_ANIMATED_GIFS
|
|
43
|
+
)
|
|
44
|
+
ImageParadise.create_animated_gif(input_images, delay)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === ImageParadise::Crop
|
|
6
|
+
#
|
|
7
|
+
# This class can be used to crop an image file via ImageMagick.
|
|
8
|
+
#
|
|
9
|
+
# Usage example:
|
|
10
|
+
# require 'crop'
|
|
11
|
+
# ImageParadise::Crop.new
|
|
12
|
+
# =========================================================================== #
|
|
13
|
+
# require 'image_paradise/crop.rb'
|
|
14
|
+
# =========================================================================== #
|
|
15
|
+
require 'image_paradise/base/base.rb'
|
|
16
|
+
|
|
17
|
+
module ImageParadise
|
|
18
|
+
|
|
19
|
+
class Crop < ::ImageParadise::Base # === ImageParadise::Crop
|
|
20
|
+
|
|
21
|
+
# ========================================================================= #
|
|
22
|
+
# === CROP_COMMAND_TO_USE
|
|
23
|
+
# ========================================================================= #
|
|
24
|
+
CROP_COMMAND_TO_USE = '125x125+35+35'
|
|
25
|
+
|
|
26
|
+
# ========================================================================= #
|
|
27
|
+
# === CONVERT_COMMAND
|
|
28
|
+
# ========================================================================= #
|
|
29
|
+
CONVERT_COMMAND = 'convert'
|
|
30
|
+
|
|
31
|
+
# ========================================================================= #
|
|
32
|
+
# === TEMP_DIR
|
|
33
|
+
# ========================================================================= #
|
|
34
|
+
TEMP_DIR = '/Depot/Temp/'
|
|
35
|
+
|
|
36
|
+
# ========================================================================= #
|
|
37
|
+
# === initialize
|
|
38
|
+
# ========================================================================= #
|
|
39
|
+
def initialize(
|
|
40
|
+
input_filename = nil,
|
|
41
|
+
use_this_crop_command = nil,
|
|
42
|
+
run_already = true
|
|
43
|
+
)
|
|
44
|
+
reset
|
|
45
|
+
case input_filename
|
|
46
|
+
when :do_not_run_yetimage_shell
|
|
47
|
+
input_filename = nil
|
|
48
|
+
run_already = false
|
|
49
|
+
end
|
|
50
|
+
set_input_filename(input_filename)
|
|
51
|
+
set_use_this_crop_command(use_this_crop_command)
|
|
52
|
+
case run_already
|
|
53
|
+
when :dont_run_yet
|
|
54
|
+
run_already = false
|
|
55
|
+
end
|
|
56
|
+
run if run_already
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# ========================================================================= #
|
|
60
|
+
# === reset (reset tag)
|
|
61
|
+
# ========================================================================= #
|
|
62
|
+
def reset
|
|
63
|
+
@be_verbose = true
|
|
64
|
+
@temp_dir = TEMP_DIR
|
|
65
|
+
@temp_dir = (Dir.pwd+'/').squeeze '/'
|
|
66
|
+
set_input_filename
|
|
67
|
+
set_output_file
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# ========================================================================= #
|
|
71
|
+
# === input_filename?
|
|
72
|
+
# ========================================================================= #
|
|
73
|
+
def input_filename?
|
|
74
|
+
@input_filename.to_s
|
|
75
|
+
end; alias input? input_filename? # === input?
|
|
76
|
+
|
|
77
|
+
# ========================================================================= #
|
|
78
|
+
# === crop_command?
|
|
79
|
+
# ========================================================================= #
|
|
80
|
+
def crop_command?
|
|
81
|
+
@use_this_crop_command
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# ========================================================================= #
|
|
85
|
+
# === synchronize_output_filename
|
|
86
|
+
# ========================================================================= #
|
|
87
|
+
def synchronize_output_filename
|
|
88
|
+
set_output_file :synchronize
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# ========================================================================= #
|
|
92
|
+
# === be_verbose?
|
|
93
|
+
# ========================================================================= #
|
|
94
|
+
def be_verbose?
|
|
95
|
+
@be_verbose
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# ========================================================================= #
|
|
99
|
+
# === perform_crop_action
|
|
100
|
+
#
|
|
101
|
+
# The first input shall be the filename we wish to crop.
|
|
102
|
+
#
|
|
103
|
+
# The second input shall be which specific crop command we will use.
|
|
104
|
+
# ========================================================================= #
|
|
105
|
+
def perform_crop_action(
|
|
106
|
+
crop_this_image = input?,
|
|
107
|
+
use_this_crop_command = crop_command?
|
|
108
|
+
)
|
|
109
|
+
if crop_this_image.is_a? Array
|
|
110
|
+
crop_this_image = crop_this_image.join(' ')
|
|
111
|
+
end
|
|
112
|
+
# ======================================================================= #
|
|
113
|
+
# Next convert both into Strings.
|
|
114
|
+
# ======================================================================= #
|
|
115
|
+
crop_this_image = crop_this_image.to_s
|
|
116
|
+
use_this_crop_command = use_this_crop_command.to_s
|
|
117
|
+
if use_this_crop_command.empty?
|
|
118
|
+
use_this_crop_command = DEFAULT_CROP_COMMAND_TO_USE
|
|
119
|
+
end
|
|
120
|
+
# ======================================================================= #
|
|
121
|
+
# The following means that the user passed only one +5 rather
|
|
122
|
+
# than two +5+5, hence we sanitize it here.
|
|
123
|
+
# ======================================================================= #
|
|
124
|
+
if use_this_crop_command.count('+') == 1
|
|
125
|
+
use_this_crop_command << use_this_crop_command[
|
|
126
|
+
use_this_crop_command.index('+')..-1
|
|
127
|
+
]
|
|
128
|
+
end
|
|
129
|
+
if use_this_crop_command.include? '%'
|
|
130
|
+
use_this_crop_command << 'x+0+0' unless use_this_crop_command[0,1] == 'x'
|
|
131
|
+
end
|
|
132
|
+
set_crop_command(use_this_crop_command) # Synchronize it back here.
|
|
133
|
+
opn; e 'Next cropping the image `'+sfancy(crop_this_image)+'`.'
|
|
134
|
+
_ = CONVERT_COMMAND+' '+crop_this_image+
|
|
135
|
+
' -crop '+use_this_crop_command+' '+output_file?
|
|
136
|
+
opn; Esystem.esystem(_)
|
|
137
|
+
report_where_the_file_is_now_stored if be_verbose?
|
|
138
|
+
return output_file?
|
|
139
|
+
end; alias do_crop perform_crop_action # === do_crop
|
|
140
|
+
alias crop perform_crop_action # === crop
|
|
141
|
+
|
|
142
|
+
# ========================================================================= #
|
|
143
|
+
# === report_where_the_file_is_now_stored
|
|
144
|
+
# ========================================================================= #
|
|
145
|
+
def report_where_the_file_is_now_stored
|
|
146
|
+
opn; e 'This should now be stored at '
|
|
147
|
+
opn; e " #{sfile(output_file?)}"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# ========================================================================= #
|
|
151
|
+
# === set_use_this_crop_command
|
|
152
|
+
# ========================================================================= #
|
|
153
|
+
def set_use_this_crop_command(i = nil)
|
|
154
|
+
i = CROP_COMMAND_TO_USE if i.nil?
|
|
155
|
+
i = i.join ' ' if i.is_a? Array
|
|
156
|
+
@use_this_crop_command = i
|
|
157
|
+
end; alias set_crop_command set_use_this_crop_command # === set_crop_command
|
|
158
|
+
|
|
159
|
+
# ========================================================================= #
|
|
160
|
+
# === output_file?
|
|
161
|
+
# ========================================================================= #
|
|
162
|
+
def output_file?
|
|
163
|
+
@output_file
|
|
164
|
+
end; alias result output_file? # === result
|
|
165
|
+
alias result? output_file? # === result?
|
|
166
|
+
alias output? output_file? # === output?
|
|
167
|
+
|
|
168
|
+
# ========================================================================= #
|
|
169
|
+
# === set_input_filename
|
|
170
|
+
#
|
|
171
|
+
# Whenever we modify the input filename, we also must update the
|
|
172
|
+
# output_filename.
|
|
173
|
+
# ========================================================================= #
|
|
174
|
+
def set_input_filename(i = nil)
|
|
175
|
+
i = i.first if i.is_a? Array
|
|
176
|
+
i = i.to_s.dup
|
|
177
|
+
@input_filename = i
|
|
178
|
+
synchronize_output_filename
|
|
179
|
+
end; alias input_file= set_input_filename # === input_file=
|
|
180
|
+
|
|
181
|
+
# ========================================================================= #
|
|
182
|
+
# === ImageParadise::Crop[]
|
|
183
|
+
#
|
|
184
|
+
# An alias to the above method.
|
|
185
|
+
# ========================================================================= #
|
|
186
|
+
def self.[](i, use_this_crop_command)
|
|
187
|
+
Crop.crop(i, use_this_crop_command)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# ========================================================================= #
|
|
191
|
+
# === ImageParadise::Crop.crop
|
|
192
|
+
#
|
|
193
|
+
# We purposely require two arguments here.
|
|
194
|
+
# ========================================================================= #
|
|
195
|
+
def self.crop(
|
|
196
|
+
crop_this_image,
|
|
197
|
+
use_this_crop_command,
|
|
198
|
+
optional_hash = {}
|
|
199
|
+
)
|
|
200
|
+
_ = Crop.new :do_not_run_yet
|
|
201
|
+
if optional_hash.has_key? :store_in_this_directory
|
|
202
|
+
_.set_store_here(
|
|
203
|
+
optional_hash.delete(:store_in_this_directory)
|
|
204
|
+
)
|
|
205
|
+
end
|
|
206
|
+
_.input_file = crop_this_image
|
|
207
|
+
result = _.crop(crop_this_image, use_this_crop_command)
|
|
208
|
+
return result
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# ========================================================================= #
|
|
212
|
+
# === set_output_file
|
|
213
|
+
# ========================================================================= #
|
|
214
|
+
def set_output_file(
|
|
215
|
+
i = default_name_for_cropped_image
|
|
216
|
+
)
|
|
217
|
+
if i.nil? or i == :synchronize
|
|
218
|
+
i = default_name_for_cropped_image
|
|
219
|
+
end
|
|
220
|
+
i = (Dir.pwd+'/'+i).squeeze('/') unless i.include? '/'
|
|
221
|
+
@output_file = i
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# ========================================================================= #
|
|
225
|
+
# === default_name_for_cropped_image
|
|
226
|
+
# ========================================================================= #
|
|
227
|
+
def default_name_for_cropped_image
|
|
228
|
+
temp_dir?+'CROPPED_IMAGE_'+today+'_'+File.basename(input?)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# ========================================================================= #
|
|
232
|
+
# === temp_dir?
|
|
233
|
+
# ========================================================================= #
|
|
234
|
+
def temp_dir?
|
|
235
|
+
@temp_dir
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# ========================================================================= #
|
|
239
|
+
# === set_store_here
|
|
240
|
+
# ========================================================================= #
|
|
241
|
+
def set_store_here(i)
|
|
242
|
+
i << '/' unless i.end_with? '/'
|
|
243
|
+
@temp_dir = i
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# ========================================================================= #
|
|
247
|
+
# === run_everything
|
|
248
|
+
# ========================================================================= #
|
|
249
|
+
def run_everything
|
|
250
|
+
perform_crop_action # This here will do the actual cropping.
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# ========================================================================= #
|
|
254
|
+
# === run (run tag)
|
|
255
|
+
# ========================================================================= #
|
|
256
|
+
def run
|
|
257
|
+
run_everything
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# ========================================================================= #
|
|
263
|
+
# === ImageParadise.crop
|
|
264
|
+
#
|
|
265
|
+
# Use this toplevel-method in order to crop an image.
|
|
266
|
+
#
|
|
267
|
+
# If we omit the second argument then we will use the default setting,
|
|
268
|
+
# which should be sufficiently useful enough to yield a cropped image.
|
|
269
|
+
#
|
|
270
|
+
# The "-crop" operator also understands how to crop an image to just
|
|
271
|
+
# a percentage of its original size.
|
|
272
|
+
#
|
|
273
|
+
# For example, this would half the size of the image:
|
|
274
|
+
# convert foo.png -crop 50%x+0+0 CROPPED_foo.png
|
|
275
|
+
#
|
|
276
|
+
# The first argument to this method shall be the filename that we wish
|
|
277
|
+
# to modify.
|
|
278
|
+
#
|
|
279
|
+
# The second argument is the specific image manipulation we wish to
|
|
280
|
+
# apply onto that image.
|
|
281
|
+
#
|
|
282
|
+
# Usage example:
|
|
283
|
+
# ImageParadise.crop('foo.png','40x30+10+10')
|
|
284
|
+
# ========================================================================= #
|
|
285
|
+
# Official documentation for crop-related actions in regards to
|
|
286
|
+
# ImageMagick can be found here:
|
|
287
|
+
#
|
|
288
|
+
# http://www.imagemagick.org/script/command-line-options.php?#crop
|
|
289
|
+
# ========================================================================= #
|
|
290
|
+
def self.crop(
|
|
291
|
+
i, # The input-ile is a mandatory argument.
|
|
292
|
+
crop_command_to_use = DEFAULT_CROP_COMMAND_TO_USE,
|
|
293
|
+
optional_hash = {}
|
|
294
|
+
)
|
|
295
|
+
::ImageParadise::Crop.crop(i, crop_command_to_use, optional_hash)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
if __FILE__ == $PROGRAM_NAME
|
|
301
|
+
ImageParadise::Crop.new(ARGV[0], ARGV[1])
|
|
302
|
+
end # crop
|