Skip to content

Instantly share code, notes, and snippets.

@JoshReedSchramm
Created April 6, 2011 17:51
Show Gist options
  • Save JoshReedSchramm/906133 to your computer and use it in GitHub Desktop.
Save JoshReedSchramm/906133 to your computer and use it in GitHub Desktop.
Prototyping turning an image into a masked cloud in RMagick
require "RMagick"
class CloudMasker
def initialize(destination)
@src = Magick::Image.new(190, 100)
@dst = Magick::Image.read(destination)[0]
@mask = Magick::Image.read(MASK_PATH)[0]
end
def make_cloud
@dst.resize_to_fill!(190, 100)
@dst = @dst.add_compose_mask(@mask)
@result = @dst.composite(@src, Magick::CenterGravity, Magick::OverCompositeOp)
@result = @result.add_compose_mask(@mask)
@result = @result.blur_image(0, 0.25)
@result.transparent("white").write(RESULT_PATH)
end
def self.make_image(destination)
File.delete(RESULT_PATH) if File.exist?(RESULT_PATH)
cm = CloudMasker.new(destination)
cm.make_cloud
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment