Class: Processing::Image

Inherits:
Object
  • Object
show all
Includes:
Xot::Inspectable
Defined in:
lib/processing/image.rb

Overview

Image object.

Instance Method Summary collapse

Instance Method Details

#blend(sx, sy, sw, sh, dx, dy, dw, dh, mode) ⇒ nil #blend(img, sx, sy, sw, sh, dx, dy, dw, dh, mode) ⇒ nil

Blends image.

Parameters:

  • img (Image) (defaults to: nil)

    image for blend source

  • sx (Numeric)

    x position of source region

  • sy (Numeric)

    y position of source region

  • sw (Numeric)

    width of source region

  • sh (Numeric)

    height of source region

  • dx (Numeric)

    x position of destination region

  • dy (Numeric)

    y position of destination region

  • dw (Numeric)

    width of destination region

  • dh (Numeric)

    height of destination region

  • mode (BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, EXCLUSION, MULTIPLY, SCREEN, REPLACE)

    blend mode

Returns:

  • (nil)

    nil



109
110
111
112
113
114
115
# File 'lib/processing/image.rb', line 109

def blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode)
  img ||= self
  @image.paint do |painter|
    img.drawImage__ painter, sx, sy, sw, sh, dx, dy, dw, dh, blend_mode: mode
  end
  nil
end

#copy(sx, sy, sw, sh, dx, dy, dw, dh) ⇒ nil #copy(img, sx, sy, sw, sh, dx, dy, dw, dh) ⇒ nil

Copies image.

Parameters:

  • img (Image) (defaults to: nil)

    image for copy source

  • sx (Numrtic)

    x position of source region

  • sy (Numrtic)

    y position of source region

  • sw (Numrtic)

    width of source region

  • sh (Numrtic)

    height of source region

  • dx (Numrtic)

    x position of destination region

  • dy (Numrtic)

    y position of destination region

  • dw (Numrtic)

    width of destination region

  • dh (Numrtic)

    height of destination region

Returns:

  • (nil)

    nil



87
88
89
# File 'lib/processing/image.rb', line 87

def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
  blend img, sx, sy, sw, sh, dx, dy, dw, dh, :normal
end

#filter(*args) ⇒ Object

Applies an image filter.

overload filter(shader) overload filter(type) overload filter(type, param)

Parameters:

  • shader (Shader)

    a fragment shader to apply

  • type (THRESHOLD, GRAY, INVERT, BLUR)

    filter type

  • param (Numeric)

    a parameter for each filter



52
53
54
# File 'lib/processing/image.rb', line 52

def filter(*args)
  @filter = Shader.createFilter__(*args)
end

#heightNumeric Also known as: h

Gets height of image.

Returns:

  • (Numeric)

    height of image



27
28
29
# File 'lib/processing/image.rb', line 27

def height()
  @image.height
end

#resize(width, height) ⇒ nil

Resizes image.

Parameters:

  • width (Numeric)

    width for resized image

  • height (Numeric)

    height for resized image

Returns:

  • (nil)

    nil



63
64
65
66
67
68
# File 'lib/processing/image.rb', line 63

def resize(width, height)
  @image = Rays::Image.new(width, height).paint do |painter|
    painter.image @image, 0, 0, width, height
  end
  nil
end

#save(filename) ⇒ Object

Saves image to file.

Parameters:

  • filename (String)

    file name to save image



121
122
123
# File 'lib/processing/image.rb', line 121

def save(filename)
  @image.save filename
end

#sizeArray<Numeric>

Returns the width and height of image.

Returns:

  • (Array<Numeric>)
    width, height


38
39
40
# File 'lib/processing/image.rb', line 38

def size()
  @image.size
end

#widthNumeric Also known as: w

Gets width of image.

Returns:

  • (Numeric)

    width of image



19
20
21
# File 'lib/processing/image.rb', line 19

def width()
  @image.width
end