ruby-gd 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/sample/webpng.rb ADDED
@@ -0,0 +1,111 @@
1
+ #! /usr/bin/env ruby
2
+ =begin
3
+
4
+ webpng.rb -
5
+
6
+ =end
7
+ require 'getopts'
8
+ require 'GD'
9
+
10
+ def usage
11
+ $stderr.print <<EOS
12
+ Usage: webpng.rb [-i y|n ] [-l] [-t index|none ] [-d] pngname.png
13
+ -i [y|n] Turns on/off interlace
14
+ -l Prints the table of color indexes
15
+ -t [index] Set the transparent color to the specified index (0-255 or "none")
16
+ -d Reports the dimensions and other characteristics of the image.
17
+ If you specify '-' as the input file, stdin/stdout will be used input/output.
18
+ (e.g. cat demoin.png | ./webpng.rb -i y - > demoout.png)
19
+ EOS
20
+ exit 1
21
+ end
22
+
23
+ usage if ARGV.size < 2
24
+
25
+ if ARGV[-1] == '-'
26
+ useStdinStdout = true
27
+ end
28
+
29
+ # option parse
30
+ usage unless getopts("ld", "i:", "t:", "help")
31
+ usage if $OPT_help
32
+
33
+ if $OPT_i
34
+ usage unless $OPT_i == "y" or $OPT_i == "n"
35
+ end
36
+
37
+ if $OPT_t
38
+ usage unless $OPT_t == "none" or
39
+ ($OPT_t.to_i >= 0 and $OPT_t.to_i <= 255)
40
+ end
41
+
42
+ if useStdinStdout
43
+ in_file = $stdin
44
+ else
45
+ in_fname = ARGV.pop
46
+ in_file = File.open(in_fname, "rb")
47
+ end
48
+ im = GD::Image.newFromPng(in_file)
49
+ in_file.close
50
+
51
+ # options for information displaying and exiting
52
+
53
+ if $OPT_l
54
+ printf("Index\tRed\tGreen\tBlue\n")
55
+ for j in 0 .. im.colorsTotal
56
+ rgb_ary = im.rgb(j)
57
+ printf("%d\t%d\t%d\t%d\n", j, rgb_ary[0], rgb_ary[1], rgb_ary[2])
58
+ end
59
+
60
+ im.destroy
61
+ exit 0
62
+ end
63
+
64
+ if $OPT_d
65
+ printf("Width: %d Height: %d Colors: %d\n",im.width, im.height, im.colorsTotal)
66
+ t = im.getTransparent
67
+ if t != -1
68
+ printf("Transparent index: %d\n", t)
69
+ else
70
+ puts "Transparent index: none"; # -1 means the image is not transparent.
71
+ end
72
+
73
+ if im.interlace
74
+ puts "Interlaced: yes";
75
+ else
76
+ puts "Interlaced: no";
77
+ end
78
+
79
+ im.destroy
80
+ exit 0
81
+ end
82
+
83
+ # options for involving for output part
84
+ if $OPT_i
85
+ if $OPT_i == 'y'
86
+ im.interlace = true # Set interlace
87
+ else
88
+ im.interlace = false # Clear interlace
89
+ end
90
+ end
91
+
92
+ if $OPT_t
93
+ if $OPT_t == 'none'
94
+ im.transparent(-1) # -1 means not transparent
95
+ else
96
+ im.transparent($OPT_t.to_i) # OK, get an integer and set the index
97
+ end
98
+ end
99
+
100
+ if useStdinStdout
101
+ im.png $stdout
102
+ else
103
+ o_fname = "webpng.tmp"+$$.to_s
104
+ ofile = open(o_fname, "wb")
105
+ im.png ofile
106
+ ofile.close
107
+ File.delete in_fname
108
+ File.rename o_fname, in_fname
109
+ end
110
+
111
+ im.destroy
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.1
3
+ specification_version: 1
4
+ name: ruby-gd
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.7.4
7
+ date: 2007-01-31 00:00:00 +09:00
8
+ summary: An interface to Boutell GD library
9
+ require_paths:
10
+ - lib
11
+ email: tam at kais dot kyoto-u dot ac dot jp
12
+ homepage: http://tam.0xfa.com/ruby-gd
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: GD
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ryuichi Tamura
31
+ files:
32
+ - Changes
33
+ - extconf.rb
34
+ - GD.c
35
+ - readme.en
36
+ - readme.ja
37
+ - doc/INSTALL.en
38
+ - doc/INSTALL.ja
39
+ - doc/manual.html
40
+ - doc/manual.rd
41
+ - doc/manual_index.html
42
+ - sample/example.rb
43
+ - sample/gdtestttf.png
44
+ - sample/gdtestttf.rb
45
+ - sample/webpng.rb
46
+ test_files: []
47
+
48
+ rdoc_options: []
49
+
50
+ extra_rdoc_files:
51
+ - readme.en
52
+ executables: []
53
+
54
+ extensions:
55
+ - extconf.rb
56
+ requirements: []
57
+
58
+ dependencies: []
59
+