Class: Retouch::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/retouch/pipeline.rb,
sig/retouch.rbs

Constant Summary collapse

OPERATIONS =
%i[
  resize thumbnail crop flip flop rotate pad extend border trim
  grayscale invert brightness contrast gamma saturate tint opacity quantize
  blur sharpen pixelate overlay watermark text rect arrow
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(image, operations = []) ⇒ Pipeline

Returns a new instance of Pipeline.

Raises:

  • (TypeError)


11
12
13
14
15
16
# File 'lib/retouch/pipeline.rb', line 11

def initialize(image, operations = [])
  raise TypeError, "image must be a Tessel::Image" unless image.is_a?(Tessel::Image)

  @source = image.dup
  @operations = operations.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **options, &block) ⇒ Object



31
32
33
34
35
# File 'lib/retouch/pipeline.rb', line 31

def method_missing(name, *args, **options, &block)
  return super if block || !OPERATIONS.include?(name)

  self.class.new(@source, @operations + [[name, args, options]])
end

Instance Method Details

#arrow ⇒ Pipeline

Parameters:

  • x1 (Integer)
  • y1 (Integer)
  • x2 (Integer)
  • y2 (Integer)
  • color (String)
  • options (Object)

Returns:



80
# File 'sig/retouch.rbs', line 80

def arrow: (Integer x1, Integer y1, Integer x2, Integer y2, ?String color, **untyped options) -> Pipeline

#blur ⇒ Pipeline

Parameters:

  • sigma (Numeric)

Returns:



73
# File 'sig/retouch.rbs', line 73

def blur: (Numeric sigma) -> Pipeline

#border ⇒ Pipeline

Parameters:

  • width (Integer)
  • color (String)
  • options (Object)

Returns:



62
# File 'sig/retouch.rbs', line 62

def border: (Integer width, ?String color, **untyped options) -> Pipeline

#brightness ⇒ Pipeline

Parameters:

  • amount (Numeric)

Returns:



66
# File 'sig/retouch.rbs', line 66

def brightness: (Numeric amount) -> Pipeline

#contrast ⇒ Pipeline

Parameters:

  • factor (Numeric)

Returns:



67
# File 'sig/retouch.rbs', line 67

def contrast: (Numeric factor) -> Pipeline

#crop ⇒ Pipeline

Parameters:

  • geometry (String, Geometry)
  • options (Object)

Returns:



56
# File 'sig/retouch.rbs', line 56

def crop: (String | Geometry geometry, **untyped options) -> Pipeline

#extend ⇒ Pipeline

Parameters:

  • width (Integer)
  • height (Integer)
  • options (Object)

Returns:



61
# File 'sig/retouch.rbs', line 61

def extend: (Integer width, Integer height, **untyped options) -> Pipeline

#flip ⇒ Pipeline

Returns:



57
# File 'sig/retouch.rbs', line 57

def flip: -> Pipeline

#flop ⇒ Pipeline

Returns:



58
# File 'sig/retouch.rbs', line 58

def flop: -> Pipeline

#gamma ⇒ Pipeline

Parameters:

  • value (Numeric)

Returns:



68
# File 'sig/retouch.rbs', line 68

def gamma: (Numeric value) -> Pipeline

#grayscale ⇒ Pipeline

Returns:



64
# File 'sig/retouch.rbs', line 64

def grayscale: -> Pipeline

#info ⇒ Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


25
# File 'lib/retouch/pipeline.rb', line 25

def info = Operations.info(to_image)

#invert ⇒ Pipeline

Returns:



65
# File 'sig/retouch.rbs', line 65

def invert: -> Pipeline

#opacity ⇒ Pipeline

Parameters:

  • amount (Numeric)

Returns:



71
# File 'sig/retouch.rbs', line 71

def opacity: (Numeric amount) -> Pipeline

#overlay ⇒ Pipeline

Parameters:

  • source (String, untyped)
  • options (Object)

Returns:



76
# File 'sig/retouch.rbs', line 76

def overlay: (String | untyped source, **untyped options) -> Pipeline

#pad ⇒ Pipeline

Parameters:

  • amount (Integer)
  • options (Object)

Returns:



60
# File 'sig/retouch.rbs', line 60

def pad: (Integer amount, **untyped options) -> Pipeline

#pixelate ⇒ Pipeline

Parameters:

  • size (Integer)

Returns:



75
# File 'sig/retouch.rbs', line 75

def pixelate: (Integer size) -> Pipeline

#quantize ⇒ Pipeline

Parameters:

  • options (Object)

Returns:



72
# File 'sig/retouch.rbs', line 72

def quantize: (**untyped options) -> Pipeline

#rect ⇒ Pipeline

Parameters:

  • x (Integer)
  • y (Integer)
  • width (Integer)
  • height (Integer)
  • color (String)
  • options (Object)

Returns:



79
# File 'sig/retouch.rbs', line 79

def rect: (Integer x, Integer y, Integer width, Integer height, ?String color, **untyped options) -> Pipeline

#resize ⇒ Pipeline

Parameters:

  • geometry (String, Geometry)
  • options (Object)

Returns:



54
# File 'sig/retouch.rbs', line 54

def resize: (String | Geometry geometry, **untyped options) -> Pipeline

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/retouch/pipeline.rb', line 37

def respond_to_missing?(name, include_private = false)
  OPERATIONS.include?(name) || super
end

#rotate ⇒ Pipeline

Parameters:

  • degrees (Numeric)
  • options (Object)

Returns:



59
# File 'sig/retouch.rbs', line 59

def rotate: (Numeric degrees, **untyped options) -> Pipeline

#saturate ⇒ Pipeline

Parameters:

  • factor (Numeric)

Returns:



69
# File 'sig/retouch.rbs', line 69

def saturate: (Numeric factor) -> Pipeline

#save(path, **options) ⇒ String

Parameters:

  • path (String)
  • level: (Integer)
  • strip: (Boolean)

Returns:

  • (String)


27
28
29
# File 'lib/retouch/pipeline.rb', line 27

def save(path, **options)
  ImageIO.write(to_image, String(path), **options)
end

#sharpen ⇒ Pipeline

Parameters:

  • sigma (Numeric)
  • options (Object)

Returns:



74
# File 'sig/retouch.rbs', line 74

def sharpen: (Numeric sigma, **untyped options) -> Pipeline

#text ⇒ Pipeline

Parameters:

  • text (String)
  • options (Object)

Returns:



78
# File 'sig/retouch.rbs', line 78

def text: (String text, **untyped options) -> Pipeline

#thumbnail ⇒ Pipeline

Parameters:

  • geometry (String, Geometry)
  • options (Object)

Returns:



55
# File 'sig/retouch.rbs', line 55

def thumbnail: (String | Geometry geometry, **untyped options) -> Pipeline

#tint ⇒ Pipeline

Parameters:

  • color (String)
  • options (Object)

Returns:



70
# File 'sig/retouch.rbs', line 70

def tint: (String color, **untyped options) -> Pipeline

#to_image ⇒ Object

Returns:

  • (Object)


18
19
20
21
22
23
# File 'lib/retouch/pipeline.rb', line 18

def to_image
  @operations.reduce(@source.dup) do |image, (name, args, options)|
    args = args.dup
    Operations.apply(image, name, *args, **options)
  end
end

#trim ⇒ Pipeline

Parameters:

  • options (Object)

Returns:



63
# File 'sig/retouch.rbs', line 63

def trim: (**untyped options) -> Pipeline

#watermark ⇒ Pipeline

Parameters:

  • source (String, untyped)
  • options (Object)

Returns:



77
# File 'sig/retouch.rbs', line 77

def watermark: (String | untyped source, **untyped options) -> Pipeline