imageruby-devil 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +56 -0
- data/examples/example1.rb +10 -0
- data/examples/example2.rb +16 -0
- data/lib/devil_persistor/devil_loader.rb +51 -0
- data/lib/devil_persistor/devil_persistor.rb +56 -0
- data/lib/helper/tempfile.rb +54 -0
- data/lib/imageruby-devil.rb +25 -0
- data/lib/imageruby-devil/devil_mixin.rb +90 -0
- metadata +90 -0
data/README
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= ImageRuby-Devil - Bridge between ImageRuby and Devil image library
|
2
|
+
|
3
|
+
Implements a set of features for ImageRuby using Devil image library (https://github.com/banister/devil)
|
4
|
+
|
5
|
+
* Support to load and save formats supported by devil library including jpg, tga, png, etc...
|
6
|
+
|
7
|
+
* New image operations: "alienify", "blur", "contrast", "edge_detect", "enboss", "equalize", "flip",
|
8
|
+
"gamma_correct", "mirror", "negate", "nosify", "rotate", "sharpen", "to_blob" inherited from
|
9
|
+
devil library see devil documentation at http://rdoc.info/github/banister/devil/master/Devil/Image
|
10
|
+
|
11
|
+
NOTE: imageruby-devil requires imageruby-bmp or imageruby-bmp-c gems in order to to work
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
=== Gem installation
|
16
|
+
|
17
|
+
sudo gem install imageruby-devil
|
18
|
+
|
19
|
+
== Usage
|
20
|
+
|
21
|
+
No explicit require is needed, examples
|
22
|
+
|
23
|
+
=== Example 1: PNG
|
24
|
+
|
25
|
+
require "imageruby"
|
26
|
+
|
27
|
+
include ImageRuby
|
28
|
+
|
29
|
+
# create image (red gradient and random green)
|
30
|
+
image = Image.new(255,255) {|x,y| Color.from_rgb(x,rand(200),0) }
|
31
|
+
|
32
|
+
# save image on png format
|
33
|
+
image.save("image.png", :png)
|
34
|
+
|
35
|
+
=== Example 2: Blur and mirror
|
36
|
+
|
37
|
+
require "imageruby"
|
38
|
+
|
39
|
+
include ImageRuby
|
40
|
+
|
41
|
+
# load image generated in the previous example
|
42
|
+
image = Image.from_file("image.png")
|
43
|
+
|
44
|
+
# apply blur effect
|
45
|
+
image = image.blur(10)
|
46
|
+
|
47
|
+
# mirror image
|
48
|
+
image = image.mirror
|
49
|
+
|
50
|
+
# save image on png format
|
51
|
+
image.save("image2.png", :png)
|
52
|
+
|
53
|
+
|
54
|
+
== Copying
|
55
|
+
|
56
|
+
Copyright (c) 2011 Dario Seminara, released under the GPL License (see LICENSE)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "imageruby"
|
3
|
+
|
4
|
+
include ImageRuby
|
5
|
+
|
6
|
+
# load image generated in the previous example
|
7
|
+
image = Image.from_file("image.png")
|
8
|
+
|
9
|
+
# apply blur effect
|
10
|
+
image = image.blur(10)
|
11
|
+
|
12
|
+
# mirror image
|
13
|
+
image = image.mirror
|
14
|
+
|
15
|
+
# save image on png format
|
16
|
+
image.save("image2.png", :png)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby-devil project, http://github.com/tario/imageruby-devil
|
4
|
+
|
5
|
+
Copyright (c) 2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby-devil 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-devil 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-devil. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "devil"
|
22
|
+
require "helper/tempfile"
|
23
|
+
require "imageruby"
|
24
|
+
|
25
|
+
module ImageRuby
|
26
|
+
class DevilFileLoader < ImageRuby::FileLoader
|
27
|
+
|
28
|
+
include TempFileMethods
|
29
|
+
|
30
|
+
def load(path)
|
31
|
+
|
32
|
+
if path.respond_to? :devil_path
|
33
|
+
raise UnableToLoadException
|
34
|
+
end
|
35
|
+
|
36
|
+
path2 = create_temp_path("img2") + ".bmp"
|
37
|
+
|
38
|
+
def path2.devil_path
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
use_temp_file(path2) do
|
43
|
+
Devil.with_image(path) do |img|
|
44
|
+
img.save(path2)
|
45
|
+
end
|
46
|
+
|
47
|
+
ImageRuby::FileLoader.load(path2)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby-devil project, http://github.com/tario/imageruby-devil
|
4
|
+
|
5
|
+
Copyright (c) 2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby-devil 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-devil 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-devil. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "devil"
|
22
|
+
require "helper/tempfile"
|
23
|
+
require "imageruby"
|
24
|
+
|
25
|
+
module ImageRuby
|
26
|
+
class DevilPersistor < FilePersistor
|
27
|
+
|
28
|
+
include TempFileMethods
|
29
|
+
|
30
|
+
def persist(image,path,format)
|
31
|
+
|
32
|
+
if path.respond_to? :devil_path
|
33
|
+
raise UnableToPersistException
|
34
|
+
end
|
35
|
+
|
36
|
+
tmppath = create_temp_path("img") + ".bmp"
|
37
|
+
|
38
|
+
def tmppath.devil_path
|
39
|
+
end
|
40
|
+
|
41
|
+
FilePersistor.persist(image,tmppath,:bmp)
|
42
|
+
|
43
|
+
use_temp_file(tmppath) do
|
44
|
+
begin
|
45
|
+
Devil.with_image(tmppath) do |img|
|
46
|
+
img.save(path)
|
47
|
+
end
|
48
|
+
rescue RuntimeError
|
49
|
+
raise UnableToEncodeException
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby-devil project, http://github.com/tario/imageruby-devil
|
4
|
+
|
5
|
+
Copyright (c) 2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby-devil 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-devil 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-devil. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "tempfile"
|
22
|
+
|
23
|
+
module TempFileMethods
|
24
|
+
|
25
|
+
def create_temp_file(basename, data)
|
26
|
+
tmpfile = Tempfile.new(basename)
|
27
|
+
ret = nil
|
28
|
+
begin
|
29
|
+
tmpfile.write data
|
30
|
+
tmpfile.close
|
31
|
+
ret = yield(tmpfile)
|
32
|
+
ensure
|
33
|
+
tmpfile.delete
|
34
|
+
end
|
35
|
+
|
36
|
+
ret
|
37
|
+
end
|
38
|
+
|
39
|
+
def use_temp_file(path)
|
40
|
+
begin
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
File.delete(path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_temp_path(basename)
|
48
|
+
tmpfile = Tempfile.new(basename)
|
49
|
+
tmppath = tmpfile.path
|
50
|
+
tmpfile.close
|
51
|
+
tmpfile.delete
|
52
|
+
tmppath
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby-devil project, http://github.com/tario/imageruby-devil
|
4
|
+
|
5
|
+
Copyright (c) 2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby-devil 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-devil 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-devil. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "rubygems"
|
22
|
+
require "devil_persistor/devil_persistor"
|
23
|
+
require "devil_persistor/devil_loader"
|
24
|
+
require "imageruby-devil/devil_mixin"
|
25
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of the imageruby-devil project, http://github.com/tario/imageruby-devil
|
4
|
+
|
5
|
+
Copyright (c) 2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
|
6
|
+
|
7
|
+
imageruby-devil 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-devil 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-devil. if not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
=end
|
21
|
+
require "devil"
|
22
|
+
require "helper/tempfile"
|
23
|
+
|
24
|
+
module ImageRuby
|
25
|
+
|
26
|
+
module ImageRubyDevilMixin
|
27
|
+
|
28
|
+
class << self
|
29
|
+
include TempFileMethods
|
30
|
+
end
|
31
|
+
include TempFileMethods
|
32
|
+
|
33
|
+
def self.tmppath
|
34
|
+
tmpfile = Tempfile.new("img")
|
35
|
+
path = tmpfile.path
|
36
|
+
tmpfile.close
|
37
|
+
|
38
|
+
path
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.from_devil(devil_image)
|
42
|
+
path = ImageRubyDevilMixin.tmppath+".bmp"
|
43
|
+
|
44
|
+
use_temp_file(path) do
|
45
|
+
devil_image.save(path)
|
46
|
+
Image.from_file(path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_devil
|
51
|
+
path = ImageRubyDevilMixin.tmppath+".bmp"
|
52
|
+
save(path,:bmp)
|
53
|
+
|
54
|
+
use_temp_file(path) do
|
55
|
+
if block_given?
|
56
|
+
Devil.with_image(path) do |devil_image|
|
57
|
+
yield(devil_image)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
Devil.load_image(path)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def devil
|
66
|
+
|
67
|
+
img = nil
|
68
|
+
|
69
|
+
self.to_devil do |devil_image|
|
70
|
+
yield(devil_image)
|
71
|
+
img = ImageRubyDevilMixin.from_devil(devil_image)
|
72
|
+
end
|
73
|
+
|
74
|
+
img
|
75
|
+
end
|
76
|
+
|
77
|
+
# devil methods
|
78
|
+
["alienify", "blur", "contrast", "edge_detect", "enboss", "equalize", "flip",
|
79
|
+
"gamma_correct", "mirror", "negate", "nosify", "rotate", "sharpen", "to_blob"].each do |m|
|
80
|
+
define_method m do |*args|
|
81
|
+
devil do |devil_image|
|
82
|
+
devil_image.send(m,*args)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
register_image_mixin ImageRubyDevilMixin
|
89
|
+
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imageruby-devil
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dario Seminara
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-14 00:00:00 -03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: devil
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 105
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
- 9
|
34
|
+
- 5
|
35
|
+
version: 0.1.9.5
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
description:
|
39
|
+
email: robertodarioseminara@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README
|
46
|
+
files:
|
47
|
+
- lib/imageruby-devil/devil_mixin.rb
|
48
|
+
- lib/helper/tempfile.rb
|
49
|
+
- lib/devil_persistor/devil_persistor.rb
|
50
|
+
- lib/devil_persistor/devil_loader.rb
|
51
|
+
- lib/imageruby-devil.rb
|
52
|
+
- examples/example1.rb
|
53
|
+
- examples/example2.rb
|
54
|
+
- README
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/tario/imageruby-devil
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Bridge between ImageRuby and Devil image library
|
89
|
+
test_files: []
|
90
|
+
|