skeptick 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +14 -0
- data/README.md +63 -289
- data/lib/skeptick/command.rb +8 -19
- data/lib/skeptick/convert.rb +65 -82
- data/lib/skeptick/core.rb +1 -7
- data/lib/skeptick/dsl_context.rb +32 -0
- data/lib/skeptick/sugar.rb +13 -7
- data/lib/skeptick/sugar/canvas.rb +8 -0
- data/lib/skeptick/sugar/clone.rb +9 -0
- data/lib/skeptick/sugar/compose.rb +50 -0
- data/lib/skeptick/sugar/delete.rb +9 -0
- data/lib/skeptick/sugar/draw.rb +7 -0
- data/lib/skeptick/sugar/font.rb +7 -0
- data/lib/skeptick/sugar/format.rb +7 -0
- data/lib/skeptick/sugar/geometry.rb +25 -31
- data/lib/skeptick/sugar/resized_image.rb +15 -0
- data/lib/skeptick/sugar/rounded_corners_image.rb +42 -0
- data/lib/skeptick/sugar/swap.rb +12 -0
- data/lib/skeptick/sugar/text.rb +11 -0
- data/lib/skeptick/sugar/torn_paper_image.rb +32 -0
- data/lib/skeptick/sugar/write.rb +8 -0
- data/lib/skeptick/version.rb +1 -1
- data/logo.rb +12 -11
- data/refresh_preview.scpt +1 -1
- data/skeptick.gemspec +1 -0
- data/test/convert_test.rb +128 -33
- data/test/sugar/canvas_test.rb +16 -0
- data/test/sugar/clone_test.rb +41 -0
- data/test/sugar/{composition_test.rb → compose_test.rb} +35 -87
- data/test/sugar/delete_test.rb +41 -0
- data/test/sugar/draw_test.rb +11 -0
- data/test/sugar/font_test.rb +11 -0
- data/test/sugar/format_test.rb +12 -0
- data/test/sugar/{resizing_test.rb → resized_image_test.rb} +5 -5
- data/test/sugar/rounded_corners_image_test.rb +53 -0
- data/test/sugar/swap_test.rb +28 -0
- data/test/sugar/text_test.rb +22 -0
- data/test/sugar/torn_paper_image_test.rb +53 -0
- data/test/sugar/write_test.rb +14 -0
- metadata +57 -34
- data/lib/skeptick/chain.rb +0 -55
- data/lib/skeptick/chain/dsl_context.rb +0 -21
- data/lib/skeptick/convert/dsl_context.rb +0 -27
- data/lib/skeptick/helper.rb +0 -26
- data/lib/skeptick/image.rb +0 -69
- data/lib/skeptick/image/dsl_context.rb +0 -29
- data/lib/skeptick/sugar/composition.rb +0 -55
- data/lib/skeptick/sugar/debugging.rb +0 -12
- data/lib/skeptick/sugar/drawing.rb +0 -32
- data/lib/skeptick/sugar/edges.rb +0 -70
- data/lib/skeptick/sugar/formatting.rb +0 -12
- data/lib/skeptick/sugar/resizing.rb +0 -16
- data/lib/skeptick/sugar/sequence_manipulation.rb +0 -43
- data/test/chain_test.rb +0 -94
- data/test/image_test.rb +0 -145
- data/test/sugar/debugging_test.rb +0 -24
- data/test/sugar/drawing_test.rb +0 -86
- data/test/sugar/edges_test.rb +0 -99
- data/test/sugar/formatting_test.rb +0 -19
- data/test/sugar/sequence_manipulation_test.rb +0 -98
@@ -1,29 +0,0 @@
|
|
1
|
-
module Skeptick
|
2
|
-
class Image
|
3
|
-
class DslContext
|
4
|
-
def initialize(image)
|
5
|
-
@image = image
|
6
|
-
end
|
7
|
-
|
8
|
-
def set(*args)
|
9
|
-
@image.set(*args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def apply(*args)
|
13
|
-
@image.apply(*args)
|
14
|
-
end
|
15
|
-
|
16
|
-
def image(obj)
|
17
|
-
@image.image(obj)
|
18
|
-
end
|
19
|
-
|
20
|
-
def convert(*args, &blk)
|
21
|
-
@image.convert(*args, &blk)
|
22
|
-
end
|
23
|
-
|
24
|
-
def method_missing(*args, &blk)
|
25
|
-
@image.process_method_missing(*args, &blk)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Skeptick
|
2
|
-
module Sugar
|
3
|
-
module Composition
|
4
|
-
module Helper
|
5
|
-
def compose(blending, *args, &blk)
|
6
|
-
convert(*args, &blk).tap do |c|
|
7
|
-
c.append :compose, blending.to_s
|
8
|
-
c.append :composite
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module Operators
|
14
|
-
def +(other)
|
15
|
-
compose(:over, self, other)
|
16
|
-
end
|
17
|
-
|
18
|
-
def -(other)
|
19
|
-
compose(:dstout, self, other)
|
20
|
-
end
|
21
|
-
|
22
|
-
def *(other)
|
23
|
-
compose(:multiply, self, other)
|
24
|
-
end
|
25
|
-
|
26
|
-
def /(other)
|
27
|
-
compose(:divide, self, other)
|
28
|
-
end
|
29
|
-
|
30
|
-
def &(other)
|
31
|
-
compose(:dstin, self, other) { apply '-alpha Set' }
|
32
|
-
end
|
33
|
-
|
34
|
-
def |(other)
|
35
|
-
compose(:dstover, self, other)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Include compose into external context
|
42
|
-
include Sugar::Composition::Helper
|
43
|
-
|
44
|
-
# Include compose into Image's and Convert's DSL context
|
45
|
-
class Image::DslContext; include Sugar::Composition::Helper end
|
46
|
-
class Convert::DslContext; include Sugar::Composition::Helper end
|
47
|
-
|
48
|
-
# Include compose into Image and Convert objects
|
49
|
-
class Image; include Sugar::Composition::Helper end
|
50
|
-
class Convert; include Sugar::Composition::Helper end
|
51
|
-
|
52
|
-
# Include operators into Image and Convert objects
|
53
|
-
class Image; include Sugar::Composition::Operators end
|
54
|
-
class Convert; include Sugar::Composition::Operators end
|
55
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Skeptick
|
2
|
-
module Sugar
|
3
|
-
module Drawing
|
4
|
-
def canvas(string, options = {})
|
5
|
-
if options[:size]
|
6
|
-
set '-size', options[:size]
|
7
|
-
end
|
8
|
-
|
9
|
-
set "canvas:#{string}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def draw(*args)
|
13
|
-
set '-draw', args.join(' ').shellescape
|
14
|
-
end
|
15
|
-
|
16
|
-
def write(text, options = {})
|
17
|
-
if options[:left] && options[:top]
|
18
|
-
opts = "#{options[:left]},#{options[:top]} "
|
19
|
-
end
|
20
|
-
|
21
|
-
draw "text #{opts}'#{text}'"
|
22
|
-
end
|
23
|
-
|
24
|
-
def font(name)
|
25
|
-
set '-font', name.split(/\s/).map(&:capitalize).join('-')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Image::DslContext; include Sugar::Drawing end
|
31
|
-
class Convert::DslContext; include Sugar::Drawing end
|
32
|
-
end
|
data/lib/skeptick/sugar/edges.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'skeptick/sugar/composition'
|
2
|
-
require 'skeptick/sugar/formatting'
|
3
|
-
|
4
|
-
module Skeptick
|
5
|
-
module Sugar
|
6
|
-
module Edges
|
7
|
-
def rounded_corners_image(image = nil, options = {}, &blk)
|
8
|
-
options = image.is_a?(Hash) ? image : options
|
9
|
-
radius = options[:radius] || 15
|
10
|
-
width, height = options.values_at(:width, :height)
|
11
|
-
|
12
|
-
if options[:size]
|
13
|
-
width, height = *options[:size].split('x').map(&:to_i)
|
14
|
-
end
|
15
|
-
|
16
|
-
if block_given?
|
17
|
-
image = Image.new(self, &blk)
|
18
|
-
end
|
19
|
-
|
20
|
-
border = if width && height
|
21
|
-
"roundrectangle 1,1 #{width},#{height} #{radius},#{radius}"
|
22
|
-
else
|
23
|
-
convert(image, to: 'info:') do
|
24
|
-
format "roundrectangle 1,1 %[fx:w], %[fx:h] #{radius},#{radius}"
|
25
|
-
end.execute.strip
|
26
|
-
end
|
27
|
-
|
28
|
-
compose(:dstin, image) do
|
29
|
-
convert do
|
30
|
-
set '+clone'
|
31
|
-
set :alpha, 'transparent', :background, 'none'
|
32
|
-
draw border
|
33
|
-
end
|
34
|
-
|
35
|
-
set :alpha, 'set'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def torn_paper_image(image = nil, options = {}, &blk)
|
40
|
-
options = image.is_a?(Hash) ? image : options
|
41
|
-
|
42
|
-
spread = options[:spread] || 1
|
43
|
-
blur = options[:blur] || '0x.7'
|
44
|
-
threshold = options[:threshold] || 50
|
45
|
-
|
46
|
-
if block_given?
|
47
|
-
image = Image.new(self, &blk)
|
48
|
-
end
|
49
|
-
|
50
|
-
compose(:copy_opacity, image) do
|
51
|
-
convert do
|
52
|
-
set '+clone'
|
53
|
-
apply :alpha, 'extract'
|
54
|
-
apply '-virtual-pixel', 'black'
|
55
|
-
apply :spread, spread
|
56
|
-
apply :blur, blur
|
57
|
-
apply :threshold, "#{threshold}%"
|
58
|
-
end
|
59
|
-
|
60
|
-
apply :alpha, 'off'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
include Sugar::Edges
|
67
|
-
|
68
|
-
class Image::DslContext; include Sugar::Edges end
|
69
|
-
class Convert::DslContext; include Sugar::Edges end
|
70
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Skeptick
|
2
|
-
module Sugar
|
3
|
-
module Formatting
|
4
|
-
def format(*args)
|
5
|
-
set '-format', args.join(' ').shellescape
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class Image::DslContext; include Sugar::Formatting end
|
11
|
-
class Convert::DslContext; include Sugar::Formatting end
|
12
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'skeptick/sugar/geometry'
|
2
|
-
|
3
|
-
module Skeptick
|
4
|
-
module Sugar
|
5
|
-
module Resizing
|
6
|
-
def resized_image(path, options = {})
|
7
|
-
image("#{path}[#{geometry(options)}]")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
include Sugar::Resizing
|
13
|
-
|
14
|
-
class Image::DslContext; include Sugar::Resizing end
|
15
|
-
class Convert::DslContext; include Sugar::Resizing end
|
16
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Skeptick
|
2
|
-
module Sugar
|
3
|
-
module SequenceManipulation
|
4
|
-
def clone(*args)
|
5
|
-
obj = (args.size < 2 ? args.first : args)
|
6
|
-
set(
|
7
|
-
if obj
|
8
|
-
"-clone #{Helper.object_to_index_range_list(obj)}"
|
9
|
-
else
|
10
|
-
'+clone'
|
11
|
-
end
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def delete(*args)
|
16
|
-
obj = (args.size < 2 ? args.first : args)
|
17
|
-
set(
|
18
|
-
if obj
|
19
|
-
"-delete #{Helper.object_to_index_range_list(obj)}"
|
20
|
-
else
|
21
|
-
'+delete'
|
22
|
-
end
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
def swap(*args)
|
27
|
-
set(
|
28
|
-
if args.empty?
|
29
|
-
'+swap'
|
30
|
-
elsif args.size == 2
|
31
|
-
"-swap #{args.join(',')}"
|
32
|
-
else
|
33
|
-
raise ArgumentError,
|
34
|
-
"wrong number of arguments (#{args.size} for 0, 2)"
|
35
|
-
end
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class Image::DslContext; include Sugar::SequenceManipulation end
|
42
|
-
class Convert::DslContext; include Sugar::SequenceManipulation end
|
43
|
-
end
|
data/test/chain_test.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
class ChainTest < Skeptick::TestCase
|
4
|
-
include Skeptick
|
5
|
-
|
6
|
-
def test_dsl_methods_available
|
7
|
-
assert_respond_to self, :chain
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_chaining_two_converts
|
11
|
-
cmd = chain do
|
12
|
-
convert('foo')
|
13
|
-
convert(:pipe)
|
14
|
-
end
|
15
|
-
|
16
|
-
assert_equal 'convert foo miff:- | convert miff:- miff:-', cmd.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_chaining_two_converts_to_destination
|
20
|
-
cmd = chain(to: 'baz') do
|
21
|
-
convert('foo')
|
22
|
-
convert(:pipe)
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_equal 'convert foo miff:- | convert miff:- baz', cmd.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_last_convert_destination_prevails
|
29
|
-
cmd = chain(to: 'baz') do
|
30
|
-
convert('foo')
|
31
|
-
convert(:pipe, to: 'qux')
|
32
|
-
end
|
33
|
-
|
34
|
-
assert_equal 'convert foo miff:- | convert miff:- qux', cmd.to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_pipe_or_returns_pipe_if_piping
|
38
|
-
cmd = chain do
|
39
|
-
convert('foo')
|
40
|
-
convert(pipe_or('bar'))
|
41
|
-
end
|
42
|
-
|
43
|
-
assert_equal 'convert foo miff:- | convert miff:- miff:-', cmd.to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_pipe_or_returns_path_if_not_piping
|
47
|
-
cmd = chain { convert(pipe_or('foo')) }
|
48
|
-
assert_equal 'convert foo miff:-', cmd.to_s
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_lvars_from_external_context_are_accessible
|
52
|
-
foo = 'foo'
|
53
|
-
cmd = chain { convert(foo) }
|
54
|
-
assert_equal 'convert foo miff:-', cmd.to_s
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_methods_from_external_context_are_accessible
|
58
|
-
context = Class.new do
|
59
|
-
include Skeptick
|
60
|
-
def foo; 'foo' end
|
61
|
-
def cmd; chain { convert(foo) } end
|
62
|
-
end
|
63
|
-
|
64
|
-
assert_equal 'convert foo miff:-', context.new.cmd.to_s
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_complex_piping_case
|
68
|
-
cmd = chain(to: 'foo') do
|
69
|
-
convert('resized_design', 'mask') do
|
70
|
-
set '-geometry', '-left-top'
|
71
|
-
set '-brightness-contrast', '-12x20'
|
72
|
-
end
|
73
|
-
|
74
|
-
convert('foo') do
|
75
|
-
convert('qux') do
|
76
|
-
set '+asdf'
|
77
|
-
set '+fdsa'
|
78
|
-
end
|
79
|
-
|
80
|
-
image 'bleh'
|
81
|
-
set '-resize'
|
82
|
-
end
|
83
|
-
|
84
|
-
convert('paper_path', pipe_or('paper_path')) do
|
85
|
-
set '-geometry +left+top'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
assert_equal 'convert resized_design mask -geometry -left-top ' +
|
90
|
-
'-brightness-contrast -12x20 miff:- | convert foo ' +
|
91
|
-
'\( qux \+asdf \+fdsa \) bleh -resize miff:- | convert paper_path ' +
|
92
|
-
'miff:- -geometry \+left\+top foo', cmd.to_s
|
93
|
-
end
|
94
|
-
end
|
data/test/image_test.rb
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
class ImageTest < Skeptick::TestCase
|
4
|
-
include Skeptick
|
5
|
-
|
6
|
-
def test_dsl_method_available
|
7
|
-
assert_respond_to self, :image
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_set_prepends_to_image_segment
|
11
|
-
cmd = convert do
|
12
|
-
image do
|
13
|
-
image 'bar'
|
14
|
-
set '-foo'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
assert_equal 'convert -foo bar miff:-', cmd.to_s
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_apply_appends_to_image_segment
|
22
|
-
cmd = convert do
|
23
|
-
image do
|
24
|
-
apply '-foo'
|
25
|
-
image 'bar'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
assert_equal 'convert bar -foo miff:-', cmd.to_s
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_lvars_from_external_context_are_accessible
|
33
|
-
foo = '-test'
|
34
|
-
|
35
|
-
cmd = convert do
|
36
|
-
image do
|
37
|
-
apply foo
|
38
|
-
image 'bar'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
assert_equal 'convert bar -test miff:-', cmd.to_s
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_methods_from_external_context_are_accessible
|
46
|
-
context = Class.new do
|
47
|
-
include Skeptick
|
48
|
-
def foo; :foo end
|
49
|
-
def cmd
|
50
|
-
convert do
|
51
|
-
image do
|
52
|
-
apply foo
|
53
|
-
image 'bar'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
assert_equal 'convert bar -foo miff:-', context.new.cmd.to_s
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_inject_image_into_convert
|
63
|
-
sample = image do
|
64
|
-
set :size, '400x400'
|
65
|
-
image 'tile:granite:'
|
66
|
-
apply '-brightness-contrast', '38x-33'
|
67
|
-
apply :blur, '0x0.5'
|
68
|
-
end
|
69
|
-
|
70
|
-
cmd = convert do
|
71
|
-
set '-foo'
|
72
|
-
image sample
|
73
|
-
set '-bar'
|
74
|
-
end
|
75
|
-
|
76
|
-
assert_equal 'convert -foo -size 400x400 tile:granite: ' +
|
77
|
-
'-brightness-contrast 38x-33 -blur 0x0.5 -bar miff:-', cmd.to_s
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_inject_image_into_convert_as_argument
|
81
|
-
sample = image do
|
82
|
-
set :size, '400x400'
|
83
|
-
image 'tile:granite:'
|
84
|
-
apply '-brightness-contrast', '38x-33'
|
85
|
-
apply :blur, '0x0.5'
|
86
|
-
end
|
87
|
-
|
88
|
-
cmd = convert(sample)
|
89
|
-
assert_equal 'convert -size 400x400 tile:granite: -brightness-contrast ' +
|
90
|
-
'38x-33 -blur 0x0.5 miff:-', cmd.to_s
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_declare_image_inside_convert
|
94
|
-
cmd = convert do
|
95
|
-
set '-foo'
|
96
|
-
image do
|
97
|
-
set :size, '400x400'
|
98
|
-
image 'tile:granite:'
|
99
|
-
apply '-brightness-contrast', '38x-33'
|
100
|
-
apply :blur, '0x0.5'
|
101
|
-
end
|
102
|
-
set '-bar'
|
103
|
-
end
|
104
|
-
|
105
|
-
assert_equal 'convert -foo -size 400x400 tile:granite: ' +
|
106
|
-
'-brightness-contrast 38x-33 -blur 0x0.5 -bar miff:-', cmd.to_s
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_nested_image
|
110
|
-
sample = image do
|
111
|
-
set :foo
|
112
|
-
image 'bar'
|
113
|
-
apply :baz
|
114
|
-
end
|
115
|
-
|
116
|
-
cmd = convert do
|
117
|
-
image do
|
118
|
-
set :size, '400x400'
|
119
|
-
image sample
|
120
|
-
apply '-brightness-contrast', '38x-33'
|
121
|
-
apply :blur, '0x0.5'
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
assert_equal 'convert -size 400x400 -foo bar -baz -brightness-contrast ' +
|
126
|
-
'38x-33 -blur 0x0.5 miff:-', cmd.to_s
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_convert_as_image_object
|
130
|
-
sample = convert('foo', to: 'bar') do
|
131
|
-
set :baz
|
132
|
-
end
|
133
|
-
|
134
|
-
cmd = convert do
|
135
|
-
image do
|
136
|
-
set '-setting'
|
137
|
-
image sample
|
138
|
-
apply '-operation'
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
assert_equal 'convert -setting ( foo -baz ) -operation miff:-',
|
143
|
-
cmd.to_s
|
144
|
-
end
|
145
|
-
end
|