quilt 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2UwNjYzYmU1MTJkNTg3MzljZDkyOTY0NjViZTlhYTg2MzY1MjhjOQ==
5
- data.tar.gz: !binary |-
6
- ZTAyNGU1N2U1YTAwMzQ1ZWRmN2VhZWJhODNmMjZlNThjMjIxMWZjZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDVlMmJjNzljNjAyMWRkY2FjNGJmMGE2ZTY1NjAzNTUyOTEwNmU2NWNlYzRm
10
- MzFkYmM3ZWIzYTk4MDY0MGJmNmJmYWRkNDk3MDcxZDQzNGFkZDJhN2ZmMGU2
11
- ZjUwMzUwODVlZDhlYTdmZGRiMDc0NjY4YjA3ZmIyZmZmNDM1MWI=
12
- data.tar.gz: !binary |-
13
- N2QwOThlNjk4ZDBlY2Q4ZWZjYzA2NWMyYWNhN2UzZGRhNTAyZDJiZTc1NGY4
14
- MTgxNjg4MzFhMWFmMDc5NTUyMWUxNzc0YzIyMjM4YWJmYmIxYjk0MWNmYjc2
15
- YjZiY2M5Y2MzOWRmODI1NmE3ZTkxNGQ1NWM3OTliMDNjZDZhNjc=
2
+ SHA1:
3
+ metadata.gz: 49c7f7200f1db6b3653b1365badc140a6ee76bf4
4
+ data.tar.gz: 277abcc41fa1cafa27c9a0f99489ac12d538ee0f
5
+ SHA512:
6
+ metadata.gz: 74e214842d20758249bea661edc432ca8c172cb1237a02ce67a9709d5292c53df18dfacab3d9567d68239f54b98085414865edbbdfd8486c3b632f48c83bb573
7
+ data.tar.gz: 49b75db2774830fccdffa1dd2941d7df2312895d714e82092e2f947aaafebc7c6f0013f142634a4a6c58a0b2a860e46eb73ce71c1e2feace7d70ed725b8e3fee
data/README.md CHANGED
@@ -8,8 +8,12 @@ A Ruby library for generating identicon.
8
8
 
9
9
  Identicon: http://en.wikipedia.org/wiki/Identicon
10
10
 
11
+ ## Updates
12
+
13
+ 2014-11-03T02:05:32+09:00 Add transparent background option
14
+
11
15
  ## Installation
12
- Required rmagick or ruby-gd.
16
+ Required rmagick or ruby-gd. (default rmagick)
13
17
 
14
18
  gem install quilt
15
19
 
@@ -42,6 +46,11 @@ Required rmagick or ruby-gd.
42
46
  identicon = Quilt::Identicon.new 'sample'
43
47
  identicon.write 'sample15_15_gd.png'
44
48
 
49
+ # output: 150 * 150 png tranparent background
50
+ identicon = Quilt::Identicon.new 'sample', :scale => 10, :transparent => true
51
+ identicon.write 'sample_t_150_150.png'
52
+
53
+
45
54
  ## Information
46
55
 
47
56
  Copyright (c) 2008 swdyh
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'bundler/gem_tasks'
4
4
 
5
5
  spec = Gem::Specification.new do |s|
6
6
  s.name = "quilt"
7
- s.version = "0.0.8"
7
+ s.version = "0.0.9"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.has_rdoc = false
10
10
  s.summary = "A Ruby library for generating identicon."
@@ -4,7 +4,7 @@ require 'digest/sha1'
4
4
 
5
5
  module Quilt
6
6
  class ImageRmagick
7
- def initialize width, height
7
+ def initialize width, height, opt = {}
8
8
  begin
9
9
  require 'rmagick'
10
10
  rescue LoadError
@@ -12,7 +12,9 @@ module Quilt
12
12
  rescue LoadError
13
13
  puts "WARNING: Failed to require rmagick, image generation will fail"
14
14
  end
15
- @image = Magick::Image.new width, height
15
+ @image = Magick::Image.new width, height do |c|
16
+ c.background_color = 'Transparent' if opt[:transparent]
17
+ end
16
18
  @image.format = 'png'
17
19
  end
18
20
 
@@ -40,6 +42,20 @@ module Quilt
40
42
  end
41
43
  end
42
44
 
45
+ def polygon_clip points
46
+ unless points.empty?
47
+ clip_img = Magick::Image.new(@image.rows, @image.rows)
48
+ dr = Magick::Draw.new
49
+ dr.polygon(*points.flatten)
50
+ dr.draw(clip_img)
51
+ clip_img_t = clip_img.transparent('white', Magick::TransparentOpacity)
52
+ f = @image.format
53
+ @image = clip_img_t.composite(@image,
54
+ Magick::CenterGravity, Magick::OutCompositeOp)
55
+ @image.format = f
56
+ end
57
+ end
58
+
43
59
  def write path
44
60
  open(path, 'wb') {|f| f.write @image.to_blob }
45
61
  end
@@ -54,7 +70,7 @@ module Quilt
54
70
  end
55
71
 
56
72
  class ImageGD
57
- def initialize width, height
73
+ def initialize width, height, opt = {}
58
74
  require 'GD'
59
75
  @image = GD::Image.new width, height
60
76
  end
@@ -139,11 +155,11 @@ module Quilt
139
155
  @scale = opt[:scale] || 1
140
156
  end
141
157
 
158
+ @transparent = !!opt[:transparent]
142
159
  @patch_width = PATCH_SIZE * @scale
143
- @image = @@image_lib.new @patch_width * 3, @patch_width * 3
160
+ @image = @@image_lib.new @patch_width * 3, @patch_width * 3, :transparent => @transparent
144
161
  @back_color = @image.color 255, 255, 255
145
162
  @fore_color = @image.color @decode[:red], @decode[:green], @decode[:blue]
146
- @image.transparent @back_color
147
163
  render
148
164
  end
149
165
 
@@ -195,6 +211,10 @@ module Quilt
195
211
  else
196
212
  fore, back = @fore_color, @back_color
197
213
  end
214
+
215
+ if @transparent && back == @back_color
216
+ back = 'Transparent'
217
+ end
198
218
  @image.fill_rect(x, y, x + @patch_width - 1, y + @patch_width - 1, back)
199
219
 
200
220
  points = []
@@ -215,7 +235,16 @@ module Quilt
215
235
  end
216
236
  points << [x + px, y + py]
217
237
  end
218
- @image.polygon points, fore
238
+
239
+ if @transparent && @@image_lib == Quilt::ImageRmagick
240
+ if fore == @back_color
241
+ @image.polygon_clip points
242
+ else
243
+ @image.polygon points, fore
244
+ end
245
+ else
246
+ @image.polygon points, fore
247
+ end
219
248
  end
220
249
 
221
250
  def write path = "#{@code}.png"
@@ -269,4 +298,3 @@ module Quilt
269
298
  end
270
299
  end
271
300
  end
272
-
@@ -2,18 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "quilt"
5
- s.version = "0.0.8"
5
+ s.version = "0.0.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["swdyh"]
9
- s.date = "2013-08-22"
9
+ s.date = "2014-11-02"
10
10
  s.description = "A Ruby library for generating identicon.\nhttps://github.com/swdyh/quilt"
11
11
  s.email = "youhei@gmail.com"
12
12
  s.files = [".travis.yml", "ChangeLog", "Gemfile", "MIT-LICENSE", "README.md", "Rakefile", "lib/quilt.rb", "quilt.gemspec", "test/quilt_test.rb", "test/test_helper.rb"]
13
13
  s.homepage = "https://github.com/swdyh/quilt"
14
14
  s.licenses = ["MIT"]
15
15
  s.require_paths = ["lib"]
16
- s.rubygems_version = "2.0.7"
16
+ s.rubygems_version = "2.0.2"
17
17
  s.summary = "A Ruby library for generating identicon."
18
18
  s.test_files = ["test/test_helper.rb"]
19
19
 
@@ -49,7 +49,7 @@ class QultTest < Test::Unit::TestCase
49
49
 
50
50
  def test_image_lib
51
51
  image_other = Class.new do
52
- def initialize a, b; end
52
+ def initialize a, b, opt = {}; end
53
53
  def method_missing *arg; end
54
54
  def write path; open(path, 'w') {|f| f.puts 'other' }; end
55
55
  end
metadata CHANGED
@@ -1,60 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quilt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - swdyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-22 00:00:00.000000000 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rmagick
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: ! 'A Ruby library for generating identicon.
56
-
57
- https://github.com/swdyh/quilt'
55
+ description: |-
56
+ A Ruby library for generating identicon.
57
+ https://github.com/swdyh/quilt
58
58
  email: youhei@gmail.com
59
59
  executables: []
60
60
  extensions: []
@@ -80,17 +80,17 @@ require_paths:
80
80
  - lib
81
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - ! '>='
83
+ - - '>='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ! '>='
88
+ - - '>='
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.0.7
93
+ rubygems_version: 2.0.2
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: A Ruby library for generating identicon.