teaas 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -6
- data/img/blood.gif +0 -0
- data/img/fire.gif +0 -0
- data/img/greenapple.png +0 -0
- data/img/no.png +0 -0
- data/lib/teaas.rb +20 -0
- data/lib/teaas/blood.rb +25 -0
- data/lib/teaas/fire.rb +25 -0
- data/lib/teaas/got.rb +26 -0
- data/lib/teaas/helper.rb +16 -0
- data/lib/teaas/horizontal_roller.rb +11 -0
- data/lib/teaas/intensify.rb +46 -0
- data/lib/teaas/magrittify.rb +31 -0
- data/lib/teaas/marquee.rb +79 -21
- data/lib/teaas/mirror.rb +21 -0
- data/lib/teaas/no.rb +25 -0
- data/lib/teaas/overlayer.rb +66 -0
- data/lib/teaas/parrotify.rb +49 -0
- data/lib/teaas/pulse.rb +35 -0
- data/lib/teaas/resize.rb +26 -0
- data/lib/teaas/spin.rb +55 -14
- data/lib/teaas/turboize.rb +9 -13
- data/lib/teaas/vertical_roller.rb +11 -0
- data/teaas.gemspec +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18a355e6063a1c263f226e3e1fb342108ce63e7b
|
4
|
+
data.tar.gz: e22de7d3d363e8bc51b57e901af700c20933c200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01271a554fe2f262e5d1f835713df45b25e4d9de2082e99d80efa62d301a7ec39952c5f7d708aab8652bc3d9b0862ed34eb1f1d72f5f2177b8cfc589212ae384
|
7
|
+
data.tar.gz: e22a13ee0175f2a38bd755e05083a9e6646d803e2f99ebccfb1c67807685be9d10617df5e47f84a358ace37e115e926c839f29916fc7c0e6259e5744c5a958be
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
Total Emojis as a Service (Teaas / TEAAS) is a lightweight library that wraps around [RMagick](https://github.com/rmagick/rmagick) and allows easy manipulation of emojis or emoji-like GIFs. Right now, it supports "Turbo"ing the emoji, making it spin, or making a marquee. This is a very early version, with more features and bug fixes to come in the future.
|
6
6
|
|
7
|
+
Version `1.0.0.bacon` and higher changes APIs from any prior versions, so make sure to check the documentation.
|
8
|
+
|
7
9
|
## Requirements
|
8
10
|
|
9
11
|
- Ruby 1.9.2 or higher
|
@@ -15,18 +17,32 @@ Total Emojis as a Service (Teaas / TEAAS) is a lightweight library that wraps ar
|
|
15
17
|
|
16
18
|
### Spin
|
17
19
|
|
18
|
-
Spinning an image just takes the image that is input and makes it spin clockwise.
|
20
|
+
Spinning an image just takes the image that is input and makes it spin clockwise or counterclockwise. Additionally, it can now spin animated GIFs, as long as the option is selected. Otherwise, will spin a single frame of the GIF.
|
19
21
|
|
20
|
-
**NOTE**: Spinning
|
22
|
+
**NOTE**: Spinning only works best on images that are square (32x32 for example). Images that are not square may return unexpected results.
|
21
23
|
|
22
24
|
**NOTE**: Spinning removes any transparency from the image.
|
23
25
|
|
24
|
-
### Marquee
|
26
|
+
### Marquee
|
25
27
|
|
26
28
|
Making an image a marquee involves taking a static image, and making intermediate images so that when the emojis are next to each other, they look like they're flowing together (like a marquee). It's best to try it out and see the results.
|
27
29
|
|
28
30
|
**NOTE**: Marquee removes any transparency from the image.
|
29
31
|
|
32
|
+
**NOTE**: Marquee supports aniamted GIFs, however depending on the type of GIF, it may not work properly.
|
33
|
+
|
34
|
+
### Blood
|
35
|
+
|
36
|
+
This overlays a blood animation over the image. Only works for static images, or a single frame of the GIF.
|
37
|
+
|
38
|
+
**NOTE**: Blood removes any transparency from the image.
|
39
|
+
|
40
|
+
### Fire
|
41
|
+
|
42
|
+
This overlays a fire animation over the image. Only works for static images, or a single frame of the GIF.
|
43
|
+
|
44
|
+
**NOTE**: Fire removes any transparency from the image.
|
45
|
+
|
30
46
|
## Documentation
|
31
47
|
Docs are in [YARD](http://yardoc.org/) format. To build the HTML docs, just `gem install yard` then run `yard`. If you'd rather not use YARD, you can just read the documentation for the methods in the source files.
|
32
48
|
|
@@ -88,15 +104,51 @@ final_result = Teaas::Turbo.turbo(marquee_result, false)
|
|
88
104
|
|
89
105
|
### From a `Magick::ImageList`
|
90
106
|
```ruby
|
91
|
-
image = Magick::
|
92
|
-
|
93
|
-
//populate image here
|
107
|
+
image = Magick::Image.read("file.png")
|
94
108
|
|
95
109
|
marquee_result = Teaas::Marquee.marquee(image)
|
96
110
|
final_result = Teaas::Turbo.turbo(marquee_result, false)
|
97
111
|
// final_result contains an array of image blobs
|
98
112
|
```
|
99
113
|
|
114
|
+
## Bloodify
|
115
|
+
### From a file
|
116
|
+
```ruby
|
117
|
+
image_path = "image.gif"
|
118
|
+
|
119
|
+
bloodify_result = Teaas::Blood.blood_from_file(image_path)
|
120
|
+
final_result = Teaas::Turbo.turbo(blood_result, false)
|
121
|
+
// final_result contains an array of image blobs
|
122
|
+
```
|
123
|
+
|
124
|
+
### From a `Magick::ImageList`
|
125
|
+
```ruby
|
126
|
+
image = Magick::Image.read("file.png")
|
127
|
+
|
128
|
+
blood_result = Teaas::Blood.blood(image)
|
129
|
+
final_result = Teaas::Turbo.turbo(marquee_result, false)
|
130
|
+
// final_result contains an array of image blobs
|
131
|
+
```
|
132
|
+
|
133
|
+
## Fireify
|
134
|
+
### From a file
|
135
|
+
```ruby
|
136
|
+
image_path = "image.gif"
|
137
|
+
|
138
|
+
fireify_result = Teaas::Fire.fire_from_file(image_path)
|
139
|
+
final_result = Teaas::Turbo.turbo(fire_result, false)
|
140
|
+
// final_result contains an array of image blobs
|
141
|
+
```
|
142
|
+
|
143
|
+
### From a `Magick::ImageList`
|
144
|
+
```ruby
|
145
|
+
image = Magick::Image.read("file.png")
|
146
|
+
|
147
|
+
fire_result = Teaas::Fire.fire(image)
|
148
|
+
final_result = Teaas::Turbo.turbo(marquee_result, false)
|
149
|
+
// final_result contains an array of image blobs
|
150
|
+
```
|
151
|
+
|
100
152
|
# Questions / PRs, etc.
|
101
153
|
Feel free to open a GitHub issue or file a pull request if you have a question or would like something added.
|
102
154
|
|
data/img/blood.gif
ADDED
Binary file
|
data/img/fire.gif
ADDED
Binary file
|
data/img/greenapple.png
ADDED
Binary file
|
data/img/no.png
ADDED
Binary file
|
data/lib/teaas.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
require 'rmagick'
|
2
2
|
|
3
|
+
require 'teaas/blood.rb'
|
4
|
+
require 'teaas/fire.rb'
|
5
|
+
require 'teaas/got.rb'
|
6
|
+
require 'teaas/helper.rb'
|
7
|
+
require 'teaas/horizontal_roller.rb'
|
8
|
+
require 'teaas/intensify.rb'
|
9
|
+
require 'teaas/magrittify.rb'
|
3
10
|
require 'teaas/marquee.rb'
|
11
|
+
require 'teaas/mirror.rb'
|
12
|
+
require 'teaas/no.rb'
|
13
|
+
require 'teaas/overlayer.rb'
|
14
|
+
require 'teaas/parrotify.rb'
|
15
|
+
require 'teaas/pulse.rb'
|
16
|
+
require 'teaas/resize.rb'
|
4
17
|
require 'teaas/spin.rb'
|
5
18
|
require 'teaas/turboize.rb'
|
19
|
+
require 'teaas/vertical_roller.rb'
|
20
|
+
|
21
|
+
module Teaas
|
22
|
+
def self.root
|
23
|
+
File.dirname(__FILE__) + "/.."
|
24
|
+
end
|
25
|
+
end
|
data/lib/teaas/blood.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Blood
|
3
|
+
# Takes in an image, and adds blood to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds.
|
4
|
+
#
|
5
|
+
# @param original_img [Magick::ImageList] The image to be rotated
|
6
|
+
# @return [Magick::ImageList] The spinning image
|
7
|
+
def self.blood(original_img)
|
8
|
+
Overlayer.overlay(original_img, Magick::ImageList.new(Teaas.root + "/img/blood.gif"))
|
9
|
+
end
|
10
|
+
|
11
|
+
# Takes in a path to an image, and adds blood to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds. This is a wrapper around {Teaas::Spin.spin}
|
12
|
+
#
|
13
|
+
# @param path [String] Path to the image to be spun
|
14
|
+
# @return [Magick::ImageList] The spinning image
|
15
|
+
def self.blood_from_file(path)
|
16
|
+
img = Magick::ImageList.new
|
17
|
+
|
18
|
+
# Grab the first element in array to prevent strange things when an
|
19
|
+
# animated image is submitted
|
20
|
+
img.read(path)[0]
|
21
|
+
|
22
|
+
blood(img)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/teaas/fire.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Fire
|
3
|
+
# Takes in an image, and adds flames to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds.
|
4
|
+
#
|
5
|
+
# @param original_img [Magick::ImageList] The image to be engufled in flames
|
6
|
+
# @return [Magick::ImageList] The image, now on fire
|
7
|
+
def self.fire(original_img)
|
8
|
+
Overlayer.overlay(original_img, Magick::ImageList.new(Teaas.root + "/img/fire.gif"))
|
9
|
+
end
|
10
|
+
|
11
|
+
# Takes in a path to an image, and adds flames to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds. This is a wrapper around {Teaas::Blood.blood}
|
12
|
+
#
|
13
|
+
# @param path [String] Path to the image to be engulfed in flames
|
14
|
+
# @return [Magick::ImageList] The image, now on fire
|
15
|
+
def self.fire_from_file(path)
|
16
|
+
img = Magick::ImageList.new
|
17
|
+
|
18
|
+
# Grab the first element in array to prevent strange things when an
|
19
|
+
# animated image is submitted
|
20
|
+
img.read(path)[0]
|
21
|
+
|
22
|
+
fire(img)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/teaas/got.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Got
|
3
|
+
# Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds.
|
4
|
+
#
|
5
|
+
# @param original_img [Magick::ImageList] The original image
|
6
|
+
# @return [Magick::ImageList] The resulting image
|
7
|
+
def self.got(original_img)
|
8
|
+
fire_img = Overlayer.overlay(original_img, Magick::ImageList.new(Teaas.root + "/img/fire.gif"))
|
9
|
+
Overlayer.overlay(fire_img, Magick::ImageList.new(Teaas.root + "/img/blood.gif"), :whitelisted_animation => true)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds. This is a wrapper around {Teaas::Got.got}
|
13
|
+
#
|
14
|
+
# @param path [String] Path to the image to be spun
|
15
|
+
# @return [Magick::ImageList] The spinning image
|
16
|
+
def self.got_from_file(path)
|
17
|
+
img = Magick::ImageList.new
|
18
|
+
|
19
|
+
# Grab the first element in array to prevent strange things when an
|
20
|
+
# animated image is submitted
|
21
|
+
img.read(path)[0]
|
22
|
+
|
23
|
+
got(img)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/teaas/helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Helper
|
3
|
+
def self.prepare_for_animation(img)
|
4
|
+
new_img = img[0]
|
5
|
+
new_img.dispose = Magick::BackgroundDispose
|
6
|
+
new_img.format = "gif"
|
7
|
+
new_img.background_color = "none"
|
8
|
+
|
9
|
+
new_img
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.animated_gif?(img)
|
13
|
+
img[0].format == "GIF" && img.length > 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Teaas
|
2
|
+
class HorizontalRoller
|
3
|
+
def self.roll(img, options)
|
4
|
+
if options[:reverse]
|
5
|
+
img.roll(options[:img_width] * ((options[:total_frames] - options[:frame].to_f) / options[:total_frames]), 0)
|
6
|
+
else
|
7
|
+
img.roll(options[:img_width] * (options[:frame].to_f / options[:total_frames]), 0)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Intensify
|
3
|
+
|
4
|
+
GRAVITY = [
|
5
|
+
Magick::NorthWestGravity,
|
6
|
+
Magick::SouthEastGravity,
|
7
|
+
Magick::SouthWestGravity,
|
8
|
+
Magick::NorthEastGravity,
|
9
|
+
Magick::SouthEastGravity,
|
10
|
+
Magick::NorthWestGravity,
|
11
|
+
Magick::SouthWestGravity,
|
12
|
+
]
|
13
|
+
|
14
|
+
# Takes in an image, composites a smaller version of it, then returns an animated intensified image image. Best when used with {Teaas::Turboize.turbo} to generate multiple intense speeds.
|
15
|
+
#
|
16
|
+
# @param original_img [Array] An array of [Magick::ImageList]s
|
17
|
+
# @return [Magick::ImageList] The intensified image
|
18
|
+
def self.intensify(original_img)
|
19
|
+
intensifty_image = Magick::ImageList.new
|
20
|
+
img = Teaas::Helper.prepare_for_animation(original_img)
|
21
|
+
final_img = Magick::Image.new(img.columns, img.rows)
|
22
|
+
final_img.format = "gif"
|
23
|
+
intensify_image = Magick::ImageList.new
|
24
|
+
|
25
|
+
img.change_geometry("95%x95%") do |cols, rows, i|
|
26
|
+
i.resize!(cols, rows)
|
27
|
+
end
|
28
|
+
|
29
|
+
GRAVITY.each do |g|
|
30
|
+
intensify_image << final_img.composite(img, g, Magick::OverCompositeOp)
|
31
|
+
end
|
32
|
+
|
33
|
+
intensify_image
|
34
|
+
end
|
35
|
+
|
36
|
+
# Takes in an image from a file, composites a smaller version of it, then returns an animated intensified image image. Best when used with {Teaas::Turboize.turbo} to generate multiple intense speeds. Wrapper around {Teaas::Intensifty.intensify}
|
37
|
+
#
|
38
|
+
# @param path [String] Path to the image to be created to an intensified image
|
39
|
+
# @return [Magick::ImageList] The intensified image
|
40
|
+
def self.intensify_from_file(path)
|
41
|
+
img = Magick::Image.read(path)
|
42
|
+
|
43
|
+
intensify(img)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Magrittify
|
3
|
+
# Takes in an image, and adds a green apple to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds.
|
4
|
+
#
|
5
|
+
# @param original_img [Magick::ImageList] The image
|
6
|
+
# @return [Magick::ImageList] The new image
|
7
|
+
def self.magrittify(original_img)
|
8
|
+
Overlayer.overlay(
|
9
|
+
original_img,
|
10
|
+
Magick::ImageList.new(Teaas.root + "/img/greenapple.png"),
|
11
|
+
:static_on_animated => true,
|
12
|
+
:gravity => Magick::CenterGravity,
|
13
|
+
:overlay_resize => 0.6,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Takes in a path to an image, and adds a green apple to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds. This is a wrapper around {Teaas::Magrittify.magrittify}
|
18
|
+
#
|
19
|
+
# @param path [String] Path to the image
|
20
|
+
# @return [Magick::ImageList] The new image
|
21
|
+
def self.magrittify_from_file(path)
|
22
|
+
img = Magick::ImageList.new
|
23
|
+
|
24
|
+
# Grab the first element in array to prevent strange things when an
|
25
|
+
# animated image is submitted
|
26
|
+
img.read(path)[0]
|
27
|
+
|
28
|
+
magrittify(img)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/teaas/marquee.rb
CHANGED
@@ -3,36 +3,94 @@ module Teaas
|
|
3
3
|
|
4
4
|
# Takes in an image, rolls it 20%, 40%, 60%, and 80%, then returns an animated marquee image. Best when used with {Teaas::Turboize.turbo} to generate multiple marquee speeds.
|
5
5
|
#
|
6
|
-
# @param original_img [
|
6
|
+
# @param original_img [Array] An array of [Magick::ImageList]s
|
7
7
|
# @return [Magick::ImageList] The marquee image
|
8
|
-
def self.marquee(original_img)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
marquee_image << img
|
16
|
-
marquee_image << img.roll(img_width * 0.2, 0)
|
17
|
-
marquee_image << img.roll(img_width * 0.4, 0)
|
18
|
-
marquee_image << img.roll(img_width * 0.6, 0)
|
19
|
-
marquee_image << img.roll(img_width * 0.8, 0)
|
20
|
-
|
21
|
-
marquee_image
|
8
|
+
def self.marquee(original_img, options = {})
|
9
|
+
if Helper.animated_gif?(original_img)
|
10
|
+
_marquee_animated_image(original_img, options)
|
11
|
+
else
|
12
|
+
_marquee_static_image(original_img, options)
|
13
|
+
end
|
22
14
|
end
|
23
15
|
|
24
16
|
# Takes in an image, rolls it 20%, 40%, 60%, and 80%, then returns an animated marquee image. Best when used with {Teaas::Turboize.turbo} to generate multiple marquee speeds. This is a wrapper around {Teaas::Marquee.marquee}
|
25
17
|
#
|
26
18
|
# @param path [String] Path to the image to be created to a marquee image
|
27
19
|
# @return [Magick::ImageList] The marquee image
|
28
|
-
def self.marquee_from_file(path)
|
29
|
-
img = Magick::
|
20
|
+
def self.marquee_from_file(path, options = {})
|
21
|
+
img = Magick::Image.read(path)
|
22
|
+
|
23
|
+
marquee(img, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self._marquee_animated_image(original_img, options)
|
27
|
+
img_width = original_img[0].columns
|
28
|
+
img_height = original_img[0].rows
|
29
|
+
if img_height > img_width
|
30
|
+
crop = true && options[:crop]
|
31
|
+
img_height = img_width
|
32
|
+
else
|
33
|
+
crop = false
|
34
|
+
end
|
35
|
+
|
36
|
+
original_img_list = Magick::ImageList.new
|
37
|
+
original_img.each { |img| original_img_list << img }
|
38
|
+
|
39
|
+
original_img_list = original_img_list.coalesce
|
40
|
+
|
41
|
+
frames = original_img.length
|
42
|
+
marquee_image = Magick::ImageList.new
|
30
43
|
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
original_img_list.each_with_index do |img, i|
|
45
|
+
img.crop!(Magick::CenterGravity, img_width, img_width) if crop
|
46
|
+
img.dispose = Magick::BackgroundDispose
|
47
|
+
roller = _roller(options)
|
48
|
+
marquee_image << roller.roll(
|
49
|
+
img,
|
50
|
+
:img_width => img_width,
|
51
|
+
:img_height => img_height,
|
52
|
+
:frame => i,
|
53
|
+
:total_frames => frames,
|
54
|
+
:reverse => options[:reverse],
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
marquee_image
|
59
|
+
end
|
60
|
+
|
61
|
+
def self._marquee_static_image(original_img, options)
|
62
|
+
marquee_image = Magick::ImageList.new
|
63
|
+
img = Teaas::Helper.prepare_for_animation(original_img)
|
64
|
+
|
65
|
+
img_width = img.columns
|
66
|
+
img_height = img.rows
|
67
|
+
|
68
|
+
if (img_height > img_width) && options[:crop]
|
69
|
+
img.crop_resized!(img_width, img_width, Magick::CenterGravity)
|
70
|
+
img_height = img_width
|
71
|
+
end
|
72
|
+
|
73
|
+
5.times do |i|
|
74
|
+
roller = _roller(options)
|
75
|
+
marquee_image << roller.roll(
|
76
|
+
img,
|
77
|
+
:img_width => img_width,
|
78
|
+
:img_height => img_height,
|
79
|
+
:frame => i,
|
80
|
+
:total_frames => 5,
|
81
|
+
:reverse => options[:reverse],
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
marquee_image
|
86
|
+
end
|
34
87
|
|
35
|
-
|
88
|
+
def self._roller(options)
|
89
|
+
if options[:horizontal]
|
90
|
+
Teaas::HorizontalRoller
|
91
|
+
else
|
92
|
+
Teaas::VerticalRoller
|
93
|
+
end
|
36
94
|
end
|
37
95
|
end
|
38
96
|
end
|
data/lib/teaas/mirror.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Mirror
|
3
|
+
def self.mirror(original_img, options = {})
|
4
|
+
if original_img[0].format == "GIF" && original_img.length > 1
|
5
|
+
mirrored_image = Magick::ImageList.new
|
6
|
+
original_img.each do |img|
|
7
|
+
mirrored_image << img.flop
|
8
|
+
end
|
9
|
+
mirrored_image
|
10
|
+
else
|
11
|
+
original_img[0].flop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.mirror_from_file(path, options = {})
|
16
|
+
img = Magick::Image.read(path)
|
17
|
+
|
18
|
+
mirror(img, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/teaas/no.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Teaas
|
2
|
+
class No
|
3
|
+
# Takes in an image, and adds no to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds.
|
4
|
+
#
|
5
|
+
# @param original_img [Magick::ImageList] The image to be rotated
|
6
|
+
# @return [Magick::ImageList] The spinning image
|
7
|
+
def self.no(original_img)
|
8
|
+
Overlayer.overlay(original_img, Magick::ImageList.new(Teaas.root + "/img/no.png"), :static_on_animated => true, :gravity => Magick::CenterGravity)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Takes in a path to an image, and adds no to it. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds. This is a wrapper around {Teaas::Spin.spin}
|
12
|
+
#
|
13
|
+
# @param path [String] Path to the image to be spun
|
14
|
+
# @return [Magick::ImageList] The spinning image
|
15
|
+
def self.no_from_file(path)
|
16
|
+
img = Magick::ImageList.new
|
17
|
+
|
18
|
+
# Grab the first element in array to prevent strange things when an
|
19
|
+
# animated image is submitted
|
20
|
+
img.read(path)[0]
|
21
|
+
|
22
|
+
no(img)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Overlayer
|
3
|
+
def self.overlay(original_img, overlay_img, options={})
|
4
|
+
if options[:whitelisted_animation]
|
5
|
+
overlay_animated_on_animated(original_img, overlay_img, options)
|
6
|
+
elsif options[:static_on_animated]
|
7
|
+
overlay_static_on_animated(original_img, overlay_img, options)
|
8
|
+
else
|
9
|
+
overlay_animated_on_static(original_img, overlay_img, options={})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.overlay_static_on_animated(img, overlay_img, options)
|
14
|
+
overlay_resize = options[:overlay_resize] || 1
|
15
|
+
image = Magick::ImageList.new
|
16
|
+
overlay_img.each do |image|
|
17
|
+
image.resize_to_fit!(img.columns * overlay_resize, img.rows * overlay_resize)
|
18
|
+
end
|
19
|
+
gravity = options[:gravity] || Magick::SouthGravity
|
20
|
+
|
21
|
+
overlay_img.gravity = gravity
|
22
|
+
img.each do |i|
|
23
|
+
i.composite!(overlay_img, gravity, Magick::OverCompositeOp)
|
24
|
+
end
|
25
|
+
|
26
|
+
img
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.overlay_animated_on_animated(img, overlay_img, options)
|
30
|
+
overlay_img.each do |image|
|
31
|
+
image.resize_to_fit!(img.columns, img.rows)
|
32
|
+
end
|
33
|
+
|
34
|
+
new_image = img
|
35
|
+
new_overlay_img = overlay_img
|
36
|
+
|
37
|
+
total_frames = img.length * overlay_img.length
|
38
|
+
|
39
|
+
((total_frames / img.length)-1).times do
|
40
|
+
new_image += img
|
41
|
+
end
|
42
|
+
|
43
|
+
((total_frames / overlay_img.length)-1).times do
|
44
|
+
new_overlay_img += overlay_img
|
45
|
+
end
|
46
|
+
new_image.gravity = options[:gravity] ? options[:gravity] : Magick::SouthGravity
|
47
|
+
new_image = new_image.composite_layers(new_overlay_img)
|
48
|
+
|
49
|
+
new_image
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.overlay_animated_on_static(original_img, overlay_img, options)
|
53
|
+
image = Magick::ImageList.new
|
54
|
+
img = Teaas::Helper.prepare_for_animation(original_img)
|
55
|
+
overlay_img.each do |image|
|
56
|
+
image.resize_to_fit!(img.columns, img.rows)
|
57
|
+
end
|
58
|
+
image << img
|
59
|
+
|
60
|
+
image.gravity = options[:gravity] ? options[:gravity] : Magick::SouthGravity
|
61
|
+
image = image.composite_layers(overlay_img)
|
62
|
+
|
63
|
+
image
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Parrotify
|
3
|
+
OFFSETS = [
|
4
|
+
{:x_offset => 1, :y_offset => 1},
|
5
|
+
{:x_offset => 0.8857, :y_offset => 0.98},
|
6
|
+
{:x_offset => 0.7714, :y_offset => 0.98},
|
7
|
+
{:x_offset => 0.6857, :y_offset => 1.02},
|
8
|
+
{:x_offset => 0.6571, :y_offset => 1.04},
|
9
|
+
{:x_offset => 0.7428, :y_offset => 1.08},
|
10
|
+
{:x_offset => 0.8571, :y_offset => 1.12},
|
11
|
+
{:x_offset => 0.9714, :y_offset => 1.12},
|
12
|
+
{:x_offset => 1.0571, :y_offset => 1.1},
|
13
|
+
{:x_offset => 1.0857, :y_offset => 1.08}
|
14
|
+
]
|
15
|
+
|
16
|
+
|
17
|
+
# Best when used with {Teaas::Turboize.turbo} to generate multiple intense speeds.
|
18
|
+
#
|
19
|
+
# @param original_img [Array] An array of [Magick::ImageList]s
|
20
|
+
# @return [Magick::ImageList] The parrotified image
|
21
|
+
def self.parrotify(original_img)
|
22
|
+
parrotify_image = Magick::ImageList.new
|
23
|
+
img = Teaas::Helper.prepare_for_animation(original_img)
|
24
|
+
width = img.columns
|
25
|
+
height = img.rows
|
26
|
+
final_img = Magick::Image.new(width, height)
|
27
|
+
final_img.format = "gif"
|
28
|
+
parrotify_image = Magick::ImageList.new
|
29
|
+
|
30
|
+
OFFSETS.each do |o|
|
31
|
+
x_coord = width * (1 - o[:x_offset])
|
32
|
+
y_coord = (height * (1 - o[:y_offset])) + (0.3 * height)
|
33
|
+
parrotify_image << final_img.composite(img, x_coord, y_coord, Magick::OverCompositeOp)
|
34
|
+
end
|
35
|
+
|
36
|
+
parrotify_image
|
37
|
+
end
|
38
|
+
|
39
|
+
# Best when used with {Teaas::Turboize.turbo} to generate multiple intense speeds. Wrapper around {Teaas::Parrotify.parrotify}
|
40
|
+
#
|
41
|
+
# @param path [String] Path to the image to be created to an parrotified image
|
42
|
+
# @return [Magick::ImageList] The parrotified image
|
43
|
+
def self.parrotify_from_file(path)
|
44
|
+
img = Magick::Image.read(path)
|
45
|
+
|
46
|
+
parrotify(img)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/teaas/pulse.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Pulse
|
3
|
+
|
4
|
+
# This is a snapshot of a broken version of Spin that creates a cool pulsing image.
|
5
|
+
#
|
6
|
+
# @param original_img [Magick::ImageList] The image to be rotated
|
7
|
+
# @return [Magick::ImageList] The pulsing image
|
8
|
+
def self.pulse(original_img)
|
9
|
+
pulsing_image = Magick::ImageList.new
|
10
|
+
img = Teaas::Helper.prepare_for_animation(original_img)
|
11
|
+
|
12
|
+
increment = 360 / 8
|
13
|
+
|
14
|
+
8.times do |i|
|
15
|
+
pulsing_image << img.rotate(increment * i+1).resize_to_fill(original_img.columns, original_img.rows)
|
16
|
+
end
|
17
|
+
|
18
|
+
pulsing_image
|
19
|
+
end
|
20
|
+
|
21
|
+
# This is a snapshot of a broken version of Spin that creates a cool pulsing image.
|
22
|
+
#
|
23
|
+
# @param path [String] Path to the image to be spun
|
24
|
+
# @return [Magick::ImageList] The pulsing image
|
25
|
+
def self.pulse_from_file(path)
|
26
|
+
img = Magick::ImageList.new
|
27
|
+
|
28
|
+
# Grab the first element in array to prevent strange things when an
|
29
|
+
# animated image is submitted
|
30
|
+
img.read(path)[0]
|
31
|
+
|
32
|
+
pulse(img)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/teaas/resize.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Teaas
|
2
|
+
class Resize
|
3
|
+
def self.resize(img, resize, options={})
|
4
|
+
img = img.coalesce
|
5
|
+
resize = "#{img.columns}x#{img.rows}" if resize.nil? || resize.empty?
|
6
|
+
img.each do |frame|
|
7
|
+
frame.change_geometry(resize) do |cols, rows, i|
|
8
|
+
if options[:sample]
|
9
|
+
i.sample!(cols, rows)
|
10
|
+
else
|
11
|
+
i.resize!(cols, rows)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
img
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.resize_from_file(path, resize, options={})
|
20
|
+
img = Magick::ImageList.new
|
21
|
+
img.read(path)
|
22
|
+
|
23
|
+
resize(img, resize, options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/teaas/spin.rb
CHANGED
@@ -1,35 +1,76 @@
|
|
1
1
|
module Teaas
|
2
2
|
class Spin
|
3
3
|
|
4
|
-
# Takes in an image, rotates it
|
4
|
+
# Takes in an image, rotates it based on the number of rotations specified, then returns an animated spinning image. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds.
|
5
5
|
#
|
6
6
|
# @param original_img [Magick::ImageList] The image to be rotated
|
7
7
|
# @return [Magick::ImageList] The spinning image
|
8
|
-
def self.spin(original_img)
|
9
|
-
|
10
|
-
|
11
|
-
img.format = "gif"
|
12
|
-
|
13
|
-
spinny_image << img
|
14
|
-
spinny_image << img.rotate(90)
|
15
|
-
spinny_image << img.rotate(180)
|
16
|
-
spinny_image << img.rotate(270)
|
8
|
+
def self.spin(original_img, options={})
|
9
|
+
rotations = options[:rotations] ? options[:rotations] : 4
|
10
|
+
counterclockwise = options[:counterclockwise]
|
17
11
|
|
18
|
-
|
12
|
+
if Helper.animated_gif?(original_img)
|
13
|
+
_spin_animated_image(original_img, rotations, counterclockwise)
|
14
|
+
else
|
15
|
+
_spin_static_image(original_img, rotations, counterclockwise)
|
16
|
+
end
|
19
17
|
end
|
20
18
|
|
21
|
-
# Takes in a path to an image, rotates it
|
19
|
+
# Takes in a path to an image, rotates it based on the number of rotations specified, then returns an animated spinning image. Best when used with {Teaas::Turboize.turbo} to generate multiple rotation speeds. This is a wrapper around {Teaas::Spin.spin}
|
22
20
|
#
|
23
21
|
# @param path [String] Path to the image to be spun
|
24
22
|
# @return [Magick::ImageList] The spinning image
|
25
|
-
def self.spin_from_file(path)
|
23
|
+
def self.spin_from_file(path, options={})
|
26
24
|
img = Magick::ImageList.new
|
27
25
|
|
28
26
|
# Grab the first element in array to prevent strange things when an
|
29
27
|
# animated image is submitted
|
30
28
|
img.read(path)[0]
|
31
29
|
|
32
|
-
spin(img)
|
30
|
+
spin(img, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self._increment(increment, i, counterclockwise, rotations)
|
34
|
+
if counterclockwise
|
35
|
+
increment * (rotations - (i+1))
|
36
|
+
else
|
37
|
+
increment * (i+1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self._spin_static_image(original_img, rotations, counterclockwise)
|
42
|
+
spinny_image = Magick::ImageList.new
|
43
|
+
img = Teaas::Helper.prepare_for_animation(original_img)
|
44
|
+
|
45
|
+
increment = 360 / rotations
|
46
|
+
|
47
|
+
rotations.times do |i|
|
48
|
+
temp_img = img.rotate(_increment(increment, i, counterclockwise, rotations)).crop(Magick::NorthWestGravity, original_img.columns, original_img.rows, true)
|
49
|
+
spinny_image << temp_img
|
50
|
+
end
|
51
|
+
|
52
|
+
spinny_image
|
53
|
+
end
|
54
|
+
|
55
|
+
def self._spin_animated_image(original_img, rotations, counterclockwise)
|
56
|
+
frames = original_img.length
|
57
|
+
original_img_list = Magick::ImageList.new
|
58
|
+
|
59
|
+
original_img.each { |img| original_img_list << img }
|
60
|
+
original_img_list = original_img.coalesce
|
61
|
+
spinny_image = Magick::ImageList.new
|
62
|
+
|
63
|
+
increment = 360 / rotations
|
64
|
+
|
65
|
+
rotations.times do |i|
|
66
|
+
original_img_list.each do |img|
|
67
|
+
img.dispose = Magick::BackgroundDispose
|
68
|
+
temp_img = img.rotate(_increment(increment, i, counterclockwise, rotations)).crop(Magick::NorthWestGravity, original_img_list.columns, original_img_list.rows, true)
|
69
|
+
spinny_image << temp_img
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
spinny_image
|
33
74
|
end
|
34
75
|
end
|
35
76
|
end
|
data/lib/teaas/turboize.rb
CHANGED
@@ -7,19 +7,15 @@ module Teaas
|
|
7
7
|
# @param resize [Integer or Falsey] The size of the largest dimension (eg. 32) for the image, or falsey if no resizing should occur
|
8
8
|
# @param speeds [Array] An array of Integers that determines the ticks per second for the resulting animated image
|
9
9
|
# @return [Array] An array of image blobs that match each specified speed
|
10
|
-
def self.turbo(img, resize, speeds=[2, 5, 10, 20, 30, 40])
|
11
|
-
if
|
12
|
-
|
13
|
-
img.
|
14
|
-
frame.change_geometry(resize) do |cols, rows, i|
|
15
|
-
i.resize!(cols, rows)
|
16
|
-
end
|
17
|
-
end
|
10
|
+
def self.turbo(img, resize, speeds=[2, 5, 10, 20, 30, 40], options={})
|
11
|
+
speeds = [2, 5, 10, 20, 30, 40] if speeds.nil?
|
12
|
+
if !resize.nil? && !resize.empty?
|
13
|
+
img = Teaas::Resize.resize(img, resize, options)
|
18
14
|
end
|
19
15
|
|
20
16
|
image_blobs = []
|
21
17
|
speeds.each do |turbo|
|
22
|
-
image_blobs << turboize_individual_image(img, turbo).to_blob
|
18
|
+
image_blobs << turboize_individual_image(img, turbo, options).to_blob
|
23
19
|
end
|
24
20
|
|
25
21
|
image_blobs
|
@@ -31,11 +27,11 @@ module Teaas
|
|
31
27
|
# @param resize Truthy if the image should be resized, falsey or nil if it should not
|
32
28
|
# @param speeds [Array] An array of Integers that determines the ticks per second for the resulting animated image
|
33
29
|
# @return [Array] An array of image blobs that match each specified speed
|
34
|
-
def self.turbo_from_file(path, resize, speeds=[2, 5, 10, 20, 30, 40])
|
30
|
+
def self.turbo_from_file(path, resize, speeds=[2, 5, 10, 20, 30, 40], options={})
|
35
31
|
img = Magick::ImageList.new
|
36
32
|
img.read(path)
|
37
33
|
|
38
|
-
turbo(img, resize, speeds)
|
34
|
+
turbo(img, resize, speeds, options)
|
39
35
|
end
|
40
36
|
|
41
37
|
# Takes in a `Magick::ImageList` and adjusts the GIF image delay, ticks per second, and iterations.
|
@@ -43,8 +39,8 @@ module Teaas
|
|
43
39
|
# @param img [Magick::ImageList]
|
44
40
|
# @param turbo [Integer] the ticks per second
|
45
41
|
# @return [Magick::ImageList]
|
46
|
-
def self.turboize_individual_image(img, turbo)
|
47
|
-
img.delay = 1
|
42
|
+
def self.turboize_individual_image(img, turbo, options={})
|
43
|
+
img.delay = options[:delay] || 1
|
48
44
|
img.ticks_per_second = turbo
|
49
45
|
img.iterations = 0
|
50
46
|
img
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Teaas
|
2
|
+
class VerticalRoller
|
3
|
+
def self.roll(img, options)
|
4
|
+
if options[:reverse]
|
5
|
+
img.roll(0, options[:img_height] * ((options[:total_frames] - options[:frame].to_f) / options[:total_frames]))
|
6
|
+
else
|
7
|
+
img.roll(0, options[:img_height] * (options[:frame].to_f / options[:total_frames]))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/teaas.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teaas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Rastello
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -50,10 +50,28 @@ files:
|
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE
|
52
52
|
- README.md
|
53
|
+
- img/blood.gif
|
54
|
+
- img/fire.gif
|
55
|
+
- img/greenapple.png
|
56
|
+
- img/no.png
|
53
57
|
- lib/teaas.rb
|
58
|
+
- lib/teaas/blood.rb
|
59
|
+
- lib/teaas/fire.rb
|
60
|
+
- lib/teaas/got.rb
|
61
|
+
- lib/teaas/helper.rb
|
62
|
+
- lib/teaas/horizontal_roller.rb
|
63
|
+
- lib/teaas/intensify.rb
|
64
|
+
- lib/teaas/magrittify.rb
|
54
65
|
- lib/teaas/marquee.rb
|
66
|
+
- lib/teaas/mirror.rb
|
67
|
+
- lib/teaas/no.rb
|
68
|
+
- lib/teaas/overlayer.rb
|
69
|
+
- lib/teaas/parrotify.rb
|
70
|
+
- lib/teaas/pulse.rb
|
71
|
+
- lib/teaas/resize.rb
|
55
72
|
- lib/teaas/spin.rb
|
56
73
|
- lib/teaas/turboize.rb
|
74
|
+
- lib/teaas/vertical_roller.rb
|
57
75
|
- teaas.gemspec
|
58
76
|
homepage: https://www.github.com/wjr1985/teaas/
|
59
77
|
licenses:
|