gd 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +5 -0
- data/MIT-LICENSE +21 -0
- data/README.md +4 -0
- data/Rakefile +22 -0
- data/lib/gd.rb +16 -0
- data/lib/gd/base.rb +10 -0
- data/lib/gd/image.rb +69 -0
- data/lib/gd/lib.rb +65 -0
- data/lib/gd/version.rb +3 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 312dd76081ed2c6d1bee0750ac6b199185803f7b
|
4
|
+
data.tar.gz: 661fdeee6812a870d45da8f8e32c9ba42fa69a22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9235167c055441bd22c54f33535ef0ebc68a6862cf108031f69df8a97c7bc07f73d40d4530a4c47b48cce98aa361ebba905a5034f4b604bc9937e4275cedc54
|
7
|
+
data.tar.gz: c98e00183b240c5be22a1172fe44cef57686f563a0f686639ed5a0589e55a1b1a2a93cec00db63bdcd55973f8641f0f55c5a62caef775a5eaef65b1d937477c5
|
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Matthias Grosser
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Run all tests'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.test_files = FileList['test/cases/*_test.rb']
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'GD'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README.md')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/lib/gd.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fiddle'
|
2
|
+
require 'fiddle/import'
|
3
|
+
require 'rbconfig'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module GD
|
7
|
+
PNG = 'png'
|
8
|
+
JPEG = 'jpeg'
|
9
|
+
GIF = 'gif'
|
10
|
+
FORMATS = [PNG, JPEG, GIF]
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'gd/version'
|
14
|
+
require 'gd/lib'
|
15
|
+
require 'gd/base'
|
16
|
+
require 'gd/image'
|
data/lib/gd/base.rb
ADDED
data/lib/gd/image.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module GD
|
2
|
+
class Image
|
3
|
+
include Base
|
4
|
+
|
5
|
+
class << self
|
6
|
+
protected :new
|
7
|
+
|
8
|
+
def import(filename, options = {})
|
9
|
+
format = options.delete(:format)
|
10
|
+
format = format.to_s.downcase if format
|
11
|
+
raise ArgumentError, "Unsupported format '#{format}'" if format && !FORMATS.include?(format)
|
12
|
+
format ||= format_from_filename(filename) || format_from_magic(File.binread(filename, 4))
|
13
|
+
method = { PNG => :gdImageCreateFromPng, JPEG => :gdImageCreateFromJpeg, GIF => :gdImageCreateFromGif }[format]
|
14
|
+
if ptr = File.open(filename, 'rb') { |f| GD::LIB.public_send(method, f) } and not ptr.null?
|
15
|
+
ptr.free = GD::LIB['gdImageDestroy']
|
16
|
+
struct = LIB::ImageStruct.new(ptr)
|
17
|
+
if struct.trueColor.zero?
|
18
|
+
IndexedColorImage.new(struct)
|
19
|
+
else
|
20
|
+
TrueColorImage.new(struct)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def format_from_filename(filename)
|
28
|
+
extension = File.extname(filename).downcase[1..-1]
|
29
|
+
extension = JPEG if 'jpg' == extension
|
30
|
+
extension if FORMATS.include?(extension)
|
31
|
+
end
|
32
|
+
|
33
|
+
def format_from_magic(data)
|
34
|
+
case data
|
35
|
+
when /\A\xFF\xD8/n then JPEG
|
36
|
+
when /\A\x89PNG/n then PNG
|
37
|
+
when /\AGIF8/n then GIF
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(struct)
|
44
|
+
raise ArgumentError, 'No struct given' unless struct
|
45
|
+
@struct = struct
|
46
|
+
end
|
47
|
+
|
48
|
+
def true_color?
|
49
|
+
not struct.trueColor.zero?
|
50
|
+
end
|
51
|
+
|
52
|
+
def width
|
53
|
+
struct.sx
|
54
|
+
end
|
55
|
+
|
56
|
+
def height
|
57
|
+
struct.sy
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
class IndexedColorImage < Image
|
63
|
+
private_class_method :import
|
64
|
+
end
|
65
|
+
|
66
|
+
class TrueColorImage < Image
|
67
|
+
private_class_method :import
|
68
|
+
end
|
69
|
+
end
|
data/lib/gd/lib.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module GD
|
2
|
+
|
3
|
+
module LIB
|
4
|
+
extend Fiddle::Importer
|
5
|
+
|
6
|
+
dlload case RbConfig::CONFIG['arch']
|
7
|
+
when /darwin/ then 'libgd.dylib'
|
8
|
+
when /mswin32/, /cygwin/ then 'bgd.dll'
|
9
|
+
else
|
10
|
+
'libgd.so'
|
11
|
+
end
|
12
|
+
|
13
|
+
extern 'void* gdImageCreateFromPng(void *)'
|
14
|
+
extern 'void* gdImageCreateFromGif(void *)'
|
15
|
+
extern 'void* gdImageCreateFromJpeg(void *)'
|
16
|
+
extern 'void* gdImageDestroy(void *)'
|
17
|
+
|
18
|
+
typedef_struct_gdImageStruct = [
|
19
|
+
'unsigned char **pixels',
|
20
|
+
'int sx',
|
21
|
+
'int sy',
|
22
|
+
'int colorsTotal',
|
23
|
+
'int red[256]',
|
24
|
+
'int green[256]',
|
25
|
+
'int blue[256]',
|
26
|
+
'int open[256]',
|
27
|
+
'int transparent',
|
28
|
+
'int* polyInts',
|
29
|
+
'int polyAllocated',
|
30
|
+
'void* brush',
|
31
|
+
'void* tile',
|
32
|
+
'int brushColorMap[256]',
|
33
|
+
'int tileColorMap[256]',
|
34
|
+
'int styleLength',
|
35
|
+
'int stylePos',
|
36
|
+
'int *style',
|
37
|
+
'int interlace',
|
38
|
+
'int thick',
|
39
|
+
'int alpha[256]',
|
40
|
+
'int trueColor',
|
41
|
+
'int** tpixels',
|
42
|
+
'int alphaBlendingFlag',
|
43
|
+
'int saveAlphaFlag',
|
44
|
+
# There should NEVER BE ACCESSOR MACROS FOR ITEMS BELOW HERE, so this
|
45
|
+
# part of the structure can be safely changed in new releases.
|
46
|
+
'int AA',
|
47
|
+
'int AA_color',
|
48
|
+
'int AA_dont_blend',
|
49
|
+
'int cx1',
|
50
|
+
'int cy1',
|
51
|
+
'int cx2',
|
52
|
+
'int cy2',
|
53
|
+
'unsigned int res_x',
|
54
|
+
'unsigned int res_y',
|
55
|
+
'int paletteQuantizationMethod',
|
56
|
+
'int paletteQuantizationSpeed',
|
57
|
+
'int paletteQuantizationMinQuality',
|
58
|
+
'int paletteQuantizationMaxQuality'
|
59
|
+
]
|
60
|
+
# 'gdInterpolationMethod interpolation_id',
|
61
|
+
# 'interpolation_method interpolation'
|
62
|
+
|
63
|
+
ImageStruct = struct(typedef_struct_gdImageStruct)
|
64
|
+
end
|
65
|
+
end
|
data/lib/gd/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthias Grosser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description: MIT-licensed Ruby bindings for GD2
|
84
|
+
email:
|
85
|
+
- mtgrosser@gmx.net
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- CHANGELOG
|
91
|
+
- MIT-LICENSE
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/gd.rb
|
95
|
+
- lib/gd/base.rb
|
96
|
+
- lib/gd/image.rb
|
97
|
+
- lib/gd/lib.rb
|
98
|
+
- lib/gd/version.rb
|
99
|
+
homepage: http://github.com/mtgrosser/gd
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Ruby bindings for the GD2 image manipulation library
|
123
|
+
test_files: []
|