imageruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/Rakefile +1 -1
- data/examples/gradients-output.bmp +0 -0
- data/examples/gradients-output.jpg +0 -0
- data/examples/gradients_sample.png +0 -0
- data/lib/imageruby/fileloader.rb +44 -0
- data/lib/imageruby/filepersistor.rb +44 -0
- data/lib/imageruby/image.rb +2 -7
- data/lib/imageruby/persistor/decoder_loader.rb +38 -0
- data/lib/imageruby/persistor/encoder_persistor.rb +42 -0
- data/lib/imageruby/pureruby.rb +2 -5
- data/lib/imageruby.rb +3 -0
- metadata +11 -4
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby project, http://github.com/tario/imageruby
|
4
|
+
|
5
|
+
Copyright (c) 2011 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the gnu general public license as published by
|
9
|
+
the free software foundation, either version 3 of the license, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
imageruby is distributed in the hope that it will be useful,
|
13
|
+
but without any warranty; without even the implied warranty of
|
14
|
+
merchantability or fitness for a particular purpose. see the
|
15
|
+
gnu general public license for more details.
|
16
|
+
|
17
|
+
you should have received a copy of the gnu general public license
|
18
|
+
along with imageruby. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "imageruby/abstract/subclass_enum"
|
22
|
+
|
23
|
+
module ImageRuby
|
24
|
+
class FileLoader
|
25
|
+
with_enumerable_subclasses
|
26
|
+
|
27
|
+
class UnableToLoadException < Exception
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.load(path)
|
32
|
+
FileLoader.each_subclass do |sc|
|
33
|
+
loader = sc.new
|
34
|
+
|
35
|
+
begin
|
36
|
+
return loader.load(path)
|
37
|
+
rescue UnableToLoadException
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
raise UnableToLoadException
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby project, http://github.com/tario/imageruby
|
4
|
+
|
5
|
+
Copyright (c) 2011 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the gnu general public license as published by
|
9
|
+
the free software foundation, either version 3 of the license, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
imageruby is distributed in the hope that it will be useful,
|
13
|
+
but without any warranty; without even the implied warranty of
|
14
|
+
merchantability or fitness for a particular purpose. see the
|
15
|
+
gnu general public license for more details.
|
16
|
+
|
17
|
+
you should have received a copy of the gnu general public license
|
18
|
+
along with imageruby. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "imageruby/abstract/subclass_enum"
|
22
|
+
|
23
|
+
module ImageRuby
|
24
|
+
class FilePersistor
|
25
|
+
with_enumerable_subclasses
|
26
|
+
|
27
|
+
class UnableToPersistException < Exception
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.persist(image,path,format)
|
32
|
+
FilePersistor.each_subclass do |sc|
|
33
|
+
persistor = sc.new
|
34
|
+
|
35
|
+
begin
|
36
|
+
return persistor.persist(image,path,format)
|
37
|
+
rescue UnableToPersistException
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
raise UnableToPersistException
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/imageruby/image.rb
CHANGED
@@ -22,6 +22,7 @@ require "imageruby/encoder"
|
|
22
22
|
require "imageruby/decoder"
|
23
23
|
require "imageruby/bitmap/bitmap"
|
24
24
|
require "imageruby/bitmap/rbbitmap"
|
25
|
+
require "imageruby/fileloader"
|
25
26
|
|
26
27
|
module ImageRuby
|
27
28
|
def self.register_image_mixin(modl)
|
@@ -62,13 +63,7 @@ module ImageRuby
|
|
62
63
|
|
63
64
|
# load a image from file
|
64
65
|
def self.from_file(path)
|
65
|
-
|
66
|
-
decoded = nil
|
67
|
-
File.open(path,"rb") do |file|
|
68
|
-
decoded = Decoder.decode(file.read, ImageRuby::Image)
|
69
|
-
end
|
70
|
-
|
71
|
-
decoded
|
66
|
+
FileLoader.load(path)
|
72
67
|
end
|
73
68
|
|
74
69
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby project, http://github.com/tario/imageruby
|
4
|
+
|
5
|
+
Copyright (c) 2011 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the gnu general public license as published by
|
9
|
+
the free software foundation, either version 3 of the license, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
imageruby is distributed in the hope that it will be useful,
|
13
|
+
but without any warranty; without even the implied warranty of
|
14
|
+
merchantability or fitness for a particular purpose. see the
|
15
|
+
gnu general public license for more details.
|
16
|
+
|
17
|
+
you should have received a copy of the gnu general public license
|
18
|
+
along with imageruby. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "imageruby/fileloader"
|
22
|
+
|
23
|
+
module ImageRuby
|
24
|
+
class DecoderLoader < FileLoader
|
25
|
+
def load(path)
|
26
|
+
content = nil
|
27
|
+
File.open(path,"rb") do |file|
|
28
|
+
content = file.read
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
ImageRuby::Decoder.decode(content, ImageRuby::Image)
|
33
|
+
rescue ImageRuby::Decoder::UnableToDecodeException
|
34
|
+
raise UnableToLoadException
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby project, http://github.com/tario/imageruby
|
4
|
+
|
5
|
+
Copyright (c) 2011 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the gnu general public license as published by
|
9
|
+
the free software foundation, either version 3 of the license, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
imageruby is distributed in the hope that it will be useful,
|
13
|
+
but without any warranty; without even the implied warranty of
|
14
|
+
merchantability or fitness for a particular purpose. see the
|
15
|
+
gnu general public license for more details.
|
16
|
+
|
17
|
+
you should have received a copy of the gnu general public license
|
18
|
+
along with imageruby. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "imageruby/filepersistor"
|
22
|
+
|
23
|
+
module ImageRuby
|
24
|
+
class EncoderPersistor < FilePersistor
|
25
|
+
def persist(image,path,format)
|
26
|
+
|
27
|
+
encoded_string = String.new
|
28
|
+
|
29
|
+
begin
|
30
|
+
ImageRuby::Encoder.encode(image,format,encoded_string)
|
31
|
+
|
32
|
+
File.open(path,"wb") do |file|
|
33
|
+
file.write encoded_string
|
34
|
+
end
|
35
|
+
|
36
|
+
rescue ImageRuby::Encoder::UnableToEncodeException
|
37
|
+
raise UnableToPersistException
|
38
|
+
end
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/imageruby/pureruby.rb
CHANGED
@@ -19,6 +19,7 @@ along with imageruby. if not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
|
20
20
|
=end
|
21
21
|
require "imageruby/bitmap/bitmap"
|
22
|
+
require "imageruby/filepersistor"
|
22
23
|
|
23
24
|
module ImageRuby
|
24
25
|
module PureRubyImageMethods
|
@@ -30,11 +31,7 @@ module ImageRuby
|
|
30
31
|
# image.save("output.bmp", :bmp)
|
31
32
|
#
|
32
33
|
def save(path, format)
|
33
|
-
|
34
|
-
str = String.new
|
35
|
-
encode(format,str)
|
36
|
-
file.write str
|
37
|
-
end
|
34
|
+
FilePersistor.persist(self,path,format)
|
38
35
|
end
|
39
36
|
|
40
37
|
private
|
data/lib/imageruby.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imageruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dario Seminara
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-13 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- examples/with_mask.bmp
|
32
32
|
- examples/colors.bmp
|
33
33
|
- examples/gradient0.bmp
|
34
|
+
- examples/gradients-output.bmp
|
34
35
|
- examples/sample2.bmp
|
35
36
|
- examples/gradient2.bmp
|
36
37
|
- examples/gradient1.bmp
|
@@ -40,17 +41,23 @@ files:
|
|
40
41
|
- examples/colors.rb
|
41
42
|
- examples/gradients.bmp
|
42
43
|
- examples/gradient.rb
|
44
|
+
- examples/gradients-output.jpg
|
45
|
+
- examples/gradients_sample.png
|
43
46
|
- examples/sample1.bmp
|
44
47
|
- examples/black.rb
|
45
48
|
- examples/mask_color.rb
|
49
|
+
- lib/imageruby/fileloader.rb
|
46
50
|
- lib/imageruby/color.rb
|
47
51
|
- lib/imageruby/abstract/subclass_enum.rb
|
48
52
|
- lib/imageruby/abstract/auto_require.rb
|
53
|
+
- lib/imageruby/persistor/encoder_persistor.rb
|
54
|
+
- lib/imageruby/persistor/decoder_loader.rb
|
49
55
|
- lib/imageruby/image.rb
|
50
56
|
- lib/imageruby/encoder.rb
|
51
57
|
- lib/imageruby/bitmap/bitmap.rb
|
52
58
|
- lib/imageruby/bitmap/rbbitmap.rb
|
53
59
|
- lib/imageruby/pureruby.rb
|
60
|
+
- lib/imageruby/filepersistor.rb
|
54
61
|
- lib/imageruby/decoder.rb
|
55
62
|
- lib/imageruby.rb
|
56
63
|
- spec/validation_spec.rb
|