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,102 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# Shared coded for the SVG component of the ImageParadise project
|
6
|
+
# be stored here.
|
7
|
+
# =========================================================================== #
|
8
|
+
# require 'image_paradise/svg/svg.rb'
|
9
|
+
# =========================================================================== #
|
10
|
+
module ImageParadise
|
11
|
+
|
12
|
+
module Svg # === ImageParadise::Svg
|
13
|
+
|
14
|
+
require 'image_paradise/project/project.rb'
|
15
|
+
require 'image_paradise/svg/circle.rb'
|
16
|
+
require 'image_paradise/svg/feature.rb'
|
17
|
+
require 'image_paradise/svg/rectangle.rb'
|
18
|
+
|
19
|
+
# ========================================================================= #
|
20
|
+
# === N
|
21
|
+
# ========================================================================= #
|
22
|
+
N = "\n"
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === @_
|
26
|
+
#
|
27
|
+
# This is a variable that will keep the big String.
|
28
|
+
# ========================================================================= #
|
29
|
+
@_ = ''.dup
|
30
|
+
|
31
|
+
# ========================================================================= #
|
32
|
+
# === Svg.reset
|
33
|
+
# ========================================================================= #
|
34
|
+
def self.reset
|
35
|
+
@_ = ''
|
36
|
+
end
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === Svg.strip
|
40
|
+
# ========================================================================= #
|
41
|
+
def self.strip(i)
|
42
|
+
return i.squeeze(' ')
|
43
|
+
end
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === Svg.string?
|
47
|
+
# ========================================================================= #
|
48
|
+
def self.string?
|
49
|
+
@_
|
50
|
+
end; self.instance_eval { alias [] string? } # === Svg[]
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === Svg.add
|
54
|
+
#
|
55
|
+
# Simply append onto @_.
|
56
|
+
# ========================================================================= #
|
57
|
+
def self.add(i = '')
|
58
|
+
i = i.to_s.dup
|
59
|
+
@_ << i
|
60
|
+
end
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === Svg.close_svg
|
64
|
+
#
|
65
|
+
# Simply close the <svg> tag here
|
66
|
+
# ========================================================================= #
|
67
|
+
def self.close_svg
|
68
|
+
return '</svg>'+N
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === Svg.chart_directory
|
73
|
+
#
|
74
|
+
# Give us the path towards the svg_-charts subdirectory.
|
75
|
+
# ========================================================================= #
|
76
|
+
def self.chart_directory
|
77
|
+
::ImageParadise.project_base_dir?+'charts/'
|
78
|
+
end
|
79
|
+
|
80
|
+
# ========================================================================= #
|
81
|
+
# === Svg.load_chart_module
|
82
|
+
#
|
83
|
+
# This method will load the individual .rb files from the chart/
|
84
|
+
# subdirectory. Currently this is not in use though - perhaps one
|
85
|
+
# day when I get to use the chart-svg subsection.
|
86
|
+
# ========================================================================= #
|
87
|
+
def self.load_chart_module
|
88
|
+
these_files = Svg.chart_directory+'*.rb'
|
89
|
+
Dir[these_files].each {|file|
|
90
|
+
file = 'image_paradise/svg/charts/'+File.basename(file)
|
91
|
+
require file # And require it.
|
92
|
+
}
|
93
|
+
end; load_chart_module # And call it at once.
|
94
|
+
|
95
|
+
# ========================================================================= #
|
96
|
+
# === Svg.add
|
97
|
+
# ========================================================================= #
|
98
|
+
def self.add_linebreak
|
99
|
+
add "<br>#{N}"
|
100
|
+
end
|
101
|
+
|
102
|
+
end; end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ImageParadise::ToGif
|
6
|
+
#
|
7
|
+
# This class will simply convert an image file to .gif.
|
8
|
+
#
|
9
|
+
# Usage example:
|
10
|
+
#
|
11
|
+
# ImageParadise::ToGif.new(ARGV)
|
12
|
+
#
|
13
|
+
# =========================================================================== #
|
14
|
+
# require 'image_paradise/to_gif.rb'
|
15
|
+
# =========================================================================== #
|
16
|
+
require 'image_paradise/base/base.rb'
|
17
|
+
|
18
|
+
module ImageParadise
|
19
|
+
|
20
|
+
class ToGif < ::ImageParadise::Base # === ImageParadise::ToGif
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === initialize
|
24
|
+
# ========================================================================= #
|
25
|
+
def initialize(
|
26
|
+
i = nil,
|
27
|
+
run_already = true
|
28
|
+
)
|
29
|
+
reset
|
30
|
+
set_input(i)
|
31
|
+
run if run_already
|
32
|
+
end
|
33
|
+
|
34
|
+
# ========================================================================= #
|
35
|
+
# === reset (reset tag)
|
36
|
+
# ========================================================================= #
|
37
|
+
def reset
|
38
|
+
end
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === set_input
|
42
|
+
# ========================================================================= #
|
43
|
+
def set_input(i = '')
|
44
|
+
i = i.first if i.is_a? Array
|
45
|
+
i = i.to_s.dup if i
|
46
|
+
@input = i
|
47
|
+
end
|
48
|
+
|
49
|
+
# ========================================================================= #
|
50
|
+
# === run_everything
|
51
|
+
#
|
52
|
+
# This method contains the main logic of the file.
|
53
|
+
# ========================================================================= #
|
54
|
+
def run_everything
|
55
|
+
opn; e 'Next converting '+simp(input?)+' to '+sfile(store_where?)
|
56
|
+
_ = 'convert '+input?+' '+store_where?
|
57
|
+
esystem _
|
58
|
+
if File.exist? store_where?
|
59
|
+
opn; e 'We will next try to optimize '+sfile(store_where?)
|
60
|
+
opn; e 'The old file size is: '+sfancy(File.size(store_where?).to_s)
|
61
|
+
ImageParadise::Optimizer[store_where?]
|
62
|
+
opn; e 'The new file size is: '+sfancy(File.size(store_where?).to_s)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# ========================================================================= #
|
67
|
+
# === input?
|
68
|
+
# ========================================================================= #
|
69
|
+
def input?
|
70
|
+
@input
|
71
|
+
end
|
72
|
+
|
73
|
+
# ========================================================================= #
|
74
|
+
# === store_where?
|
75
|
+
# ========================================================================= #
|
76
|
+
def store_where?
|
77
|
+
input?.gsub(File.extname(input?),'')+'.gif'
|
78
|
+
end
|
79
|
+
|
80
|
+
# ========================================================================= #
|
81
|
+
# === run
|
82
|
+
# ========================================================================= #
|
83
|
+
def run # (run tag)
|
84
|
+
run_everything
|
85
|
+
end
|
86
|
+
|
87
|
+
end; end
|
88
|
+
|
89
|
+
if __FILE__ == $PROGRAM_NAME
|
90
|
+
ImageParadise::ToGif.new(ARGV)
|
91
|
+
end # to_gif
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ImageParadise::ToJpg
|
6
|
+
#
|
7
|
+
# This class will simply convert an image file to .jpg format.
|
8
|
+
#
|
9
|
+
# Usage example:
|
10
|
+
# ImageParadise::ToJpg.new
|
11
|
+
# =========================================================================== #
|
12
|
+
# require 'image_paradise/to_jpg.rb'
|
13
|
+
# =========================================================================== #
|
14
|
+
require 'image_paradise/base/base.rb'
|
15
|
+
|
16
|
+
module ImageParadise
|
17
|
+
|
18
|
+
class ToJpg < ::ImageParadise::Base # === ImageParadise::ToJpg.new
|
19
|
+
|
20
|
+
# ========================================================================= #
|
21
|
+
# === initialize
|
22
|
+
# ========================================================================= #
|
23
|
+
def initialize(
|
24
|
+
i = nil,
|
25
|
+
run_already = true
|
26
|
+
)
|
27
|
+
reset
|
28
|
+
set_input(i)
|
29
|
+
run if run_already
|
30
|
+
end
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === reset
|
34
|
+
# ========================================================================= #
|
35
|
+
def reset # (reset tag)
|
36
|
+
end
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === set_input
|
40
|
+
# ========================================================================= #
|
41
|
+
def set_input(i = '')
|
42
|
+
i = i.first if i.is_a? Array
|
43
|
+
i = i.to_s.dup if i
|
44
|
+
@input = i
|
45
|
+
end
|
46
|
+
|
47
|
+
# ========================================================================= #
|
48
|
+
# === input?
|
49
|
+
# ========================================================================= #
|
50
|
+
def input?
|
51
|
+
@input
|
52
|
+
end
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === store_where?
|
56
|
+
# ========================================================================= #
|
57
|
+
def store_where?
|
58
|
+
input?.gsub(File.extname(input?),'')+'.jpg'
|
59
|
+
end
|
60
|
+
|
61
|
+
# ========================================================================= #
|
62
|
+
# === run_everything
|
63
|
+
# ========================================================================= #
|
64
|
+
def run_everything
|
65
|
+
opn; e 'Next converting '+simp(input?)+' to '+sfile(store_where?)
|
66
|
+
_ = 'convert '+input?+' '+store_where?
|
67
|
+
esystem _
|
68
|
+
end
|
69
|
+
|
70
|
+
# ========================================================================= #
|
71
|
+
# === run (run tag)
|
72
|
+
# ========================================================================= #
|
73
|
+
def run
|
74
|
+
run_everything
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
# =========================================================================== #
|
80
|
+
# === ImageParadise.to_jpg
|
81
|
+
# =========================================================================== #
|
82
|
+
def self.to_jpg(i = ARGV)
|
83
|
+
ImageParadise::ToJpg.new(i)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
if __FILE__ == $PROGRAM_NAME
|
89
|
+
ImageParadise::ToJpg.new(ARGV)
|
90
|
+
end # to_jpg
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'image_paradise/toplevel_methods/add_black_border_to_this_image.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'image_paradise/toplevel_methods/e.rb'
|
8
|
+
|
9
|
+
module ImageParadise
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'esystem'
|
13
|
+
rescue LoadError; end
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === ImageParadise.add_black_border_to_this_image
|
17
|
+
#
|
18
|
+
# This method will add a (black) border around the given input-image.
|
19
|
+
#
|
20
|
+
# Invocation example:
|
21
|
+
#
|
22
|
+
# ImageParadise.add_black_border_to_this_image('foobar.png',3)
|
23
|
+
#
|
24
|
+
# ========================================================================= #
|
25
|
+
def self.add_black_border_to_this_image(
|
26
|
+
file_that_is_to_be_modified = 'foobar.png',
|
27
|
+
n_pixels = '1'
|
28
|
+
)
|
29
|
+
n_pixels = n_pixels.to_s
|
30
|
+
if file_that_is_to_be_modified.is_a? Array
|
31
|
+
file_that_is_to_be_modified = file_that_is_to_be_modified.first
|
32
|
+
end
|
33
|
+
if File.exist? file_that_is_to_be_modified
|
34
|
+
extname = File.extname(file_that_is_to_be_modified) # Also has a leading '.' character.
|
35
|
+
new_filename = file_that_is_to_be_modified.sub(/#{File.extname(file_that_is_to_be_modified)}/,'')
|
36
|
+
new_filename << '_black_border_'+n_pixels+'px'
|
37
|
+
new_filename << extname
|
38
|
+
_ = 'convert '+file_that_is_to_be_modified+
|
39
|
+
' -shave '+n_pixels+'x'+n_pixels+' '\
|
40
|
+
'-bordercolor black '\
|
41
|
+
'-border '+n_pixels+' '+
|
42
|
+
new_filename
|
43
|
+
Esystem.esystem _
|
44
|
+
if File.exist? new_filename
|
45
|
+
e 'The file `'+new_filename+'` has been created.'
|
46
|
+
end
|
47
|
+
else
|
48
|
+
e 'No file exists at `'+file_that_is_to_be_modified+'`.'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
if __FILE__ == $PROGRAM_NAME
|
55
|
+
ImageParadise.add_black_border_to_this_image(ARGV)
|
56
|
+
end # bord_black1 STUDIES.png
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# We will tap into the project crop next.
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'image_paradise/toplevel_methods/crop.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'image_paradise/crop/crop.rb'
|
10
|
+
|
11
|
+
module ImageParadise
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === crop
|
15
|
+
#
|
16
|
+
# Delegate towards the class-method above, called ImageParadise.crop()
|
17
|
+
# ========================================================================= #
|
18
|
+
def crop(
|
19
|
+
i = filename?,
|
20
|
+
crop_command_to_use = nil,
|
21
|
+
optional_hash = {}
|
22
|
+
)
|
23
|
+
ImageParadise.crop(
|
24
|
+
i, crop_command_to_use, optional_hash
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'image_paradise/toplevel_methods/e.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module ImageParadise
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === ImageParadise.e
|
11
|
+
# ========================================================================= #
|
12
|
+
def self.e(i = '')
|
13
|
+
puts i
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'image_paradise/toplevel_methods/esystem.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'image_paradise/toplevel_methods/e.rb'
|
8
|
+
|
9
|
+
module ImageParadise
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === ImageParadise.esystem
|
13
|
+
# ========================================================================= #
|
14
|
+
def self.esystem(i)
|
15
|
+
e i
|
16
|
+
system(i)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'image_paradise/toplevel_methods/extract_text_from_this_image.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'image_paradise/toplevel_methods/esystem.rb'
|
8
|
+
|
9
|
+
module ImageParadise
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === ImageParadise.extract_text_from_this_image
|
13
|
+
#
|
14
|
+
# This method will use tesseract to extract/return text from the
|
15
|
+
# given image at hand.
|
16
|
+
#
|
17
|
+
# Invocation example:
|
18
|
+
#
|
19
|
+
# ImageParadise.extract_text_from_this_image('foobar.png')
|
20
|
+
# ImageParadise.extract_text_from_this_image('greyscaled_foo.jpg')
|
21
|
+
# ImageParadise.extract_text_from_this_image 'greyscaled_image.png'
|
22
|
+
#
|
23
|
+
# ========================================================================= #
|
24
|
+
def self.extract_text_from_this_image(
|
25
|
+
i,
|
26
|
+
use_this_oem_value = 1, # :default
|
27
|
+
do_show_the_command = false
|
28
|
+
)
|
29
|
+
i = i.join(' ').strip if i.is_a? Array
|
30
|
+
case use_this_oem_value
|
31
|
+
when :default
|
32
|
+
use_this_oem_value = 1
|
33
|
+
end
|
34
|
+
case do_show_the_command
|
35
|
+
when :do_show_the_command
|
36
|
+
do_show_the_command = true
|
37
|
+
end
|
38
|
+
use_this_command = "tesseract #{i} stdout -l eng --oem #{use_this_oem_value} --psm 3 2>&1"
|
39
|
+
if do_show_the_command
|
40
|
+
puts use_this_command
|
41
|
+
end
|
42
|
+
# ========================================================================= #
|
43
|
+
# An alternative to `` may be Open3.capture3(), such as like this:
|
44
|
+
# require 'open3'
|
45
|
+
# text, _, _ = Open3.capture3(use_this_command)
|
46
|
+
# puts text
|
47
|
+
# ========================================================================= #
|
48
|
+
result = `#{use_this_command}`
|
49
|
+
return result.strip
|
50
|
+
end; self.instance_eval { alias return_text_from_this_image extract_text_from_this_image } # === ImageParadise.return_text_from_this_image
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
if __FILE__ == $PROGRAM_NAME
|
55
|
+
ImageParadise.extract_text_from_this_image(ARGV)
|
56
|
+
end # extract_text_from_this_image
|