painter 0.1.3 → 0.1.4

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.
data/lib/painter.rb CHANGED
@@ -104,6 +104,9 @@ class Painter
104
104
  end
105
105
 
106
106
  def resize_to(destination)
107
+ transparency_index = CGD2::gdImageColorAllocateAlpha(destination.image_pointer, 255, 255, 255, Painter::ALPHA_TRANSPARENT)
108
+ CGD2::gdImageColorTransparent(destination.image_pointer, transparency_index)
109
+ CGD2::gdImageFill(destination.image_pointer, 0, 0, transparency_index)
107
110
  CGD2::gdImageCopyResampled(destination.image_pointer, self.image_pointer,
108
111
  0, 0, 0, 0,
109
112
  destination.info.x, destination.info.y, self.info.x, self.info.y)
data/lib/painter/cgd2.rb CHANGED
@@ -39,5 +39,11 @@ class Painter
39
39
  # gdImageDestroy(gdImagePtr im) (FUNCTION)
40
40
  attach_function :gdImageDestroy, [:pointer], :void
41
41
  attach_function :gdFree, [:pointer], :void
42
+ attach_function :gdImageColorTransparent, [:pointer, :int], :void
43
+
44
+ attach_function :gdImageColorAllocate, [:pointer, :int, :int, :int], :int
45
+ attach_function :gdImageColorAllocateAlpha, [:pointer, :int, :int, :int, :int], :int
46
+ attach_function :gdImageColorExact, [:pointer, :int, :int, :int], :int
47
+ attach_function :gdImageFill, [:pointer, :int, :int, :int], :void
42
48
  end
43
49
  end
Binary file
data/spec/integration.rb CHANGED
@@ -52,4 +52,15 @@ describe 'integration' do
52
52
  end
53
53
  end
54
54
 
55
+ it "should handle alpha channels" do
56
+ Painter.open("#{File.dirname(__FILE__)}/fixtures/image_with_alpha.png", :png) do |source|
57
+ Painter.write("#{File.dirname(__FILE__)}/output/alpha.gif", 128, 128, :gif) do |output|
58
+ source.resize_to(output)
59
+ end
60
+ Painter.write("#{File.dirname(__FILE__)}/output/alpha.png", 128, 128, :png) do |output|
61
+ source.resize_to(output)
62
+ end
63
+ end
64
+ end
65
+
55
66
  end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: painter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Sandofsky
@@ -54,10 +54,13 @@ files:
54
54
  - lib/painter/text.rb
55
55
  - lib/painter.rb
56
56
  - spec/color_spec.rb
57
+ - spec/fixtures/image_with_alpha.png
57
58
  - spec/fixtures/sample.jpg
58
59
  - spec/fixtures/Vera.ttf
59
60
  - spec/image_spec.rb
60
61
  - spec/integration.rb
62
+ - spec/output/alpha.gif
63
+ - spec/output/alpha.png
61
64
  - spec/output/captcha.png
62
65
  - spec/output/format.gif
63
66
  - spec/output/format.jpg