Module: ImageRuby::ImageRubyDevilMixin

Extended by:
TempFileMethods
Includes:
TempFileMethods
Defined in:
lib/imageruby-devil/devil_mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TempFileMethods

create_temp_file, create_temp_path, use_temp_file

Class Method Details

.from_devil(devil_image) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/imageruby-devil/devil_mixin.rb', line 41

def self.from_devil(devil_image)
  path = ImageRubyDevilMixin.tmppath+".bmp"

  use_temp_file(path) do
    devil_image.save(path)
    Image.from_file(path)
  end
end

.tmppathObject



33
34
35
36
37
38
39
# File 'lib/imageruby-devil/devil_mixin.rb', line 33

def self.tmppath
  tmpfile = Tempfile.new("img")
  path = tmpfile.path
  tmpfile.close

  path
end

Instance Method Details

#devilObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/imageruby-devil/devil_mixin.rb', line 65

def devil

  img = nil

  self.to_devil do |devil_image|
    yield(devil_image)
    img = ImageRubyDevilMixin.from_devil(devil_image)
  end

  img
end

#to_devilObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/imageruby-devil/devil_mixin.rb', line 50

def to_devil
  path = ImageRubyDevilMixin.tmppath+".bmp"
  save(path,:bmp)

  use_temp_file(path) do
    if block_given?
      Devil.with_image(path) do |devil_image|
        yield(devil_image)
      end
    else
      Devil.load_image(path)
    end
  end
end