Class: ImageProcessing::Pura::Processor

Inherits:
Pura::Processing::Processor
  • Object
show all
Defined in:
lib/image_processing/pura.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_image(path_or_image, **_options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/image_processing/pura.rb', line 30

def self.load_image(path_or_image, **_options)
  if path_or_image.is_a?(::Pura::Image::Wrapper)
    path_or_image
  elsif path_or_image.is_a?(String)
    ::Pura::Image::Processor.load(path_or_image)
  elsif path_or_image.respond_to?(:path)
    ::Pura::Image::Processor.load(path_or_image.path)
  else
    raise ::Pura::Processing::Error, "unsupported source: #{path_or_image.inspect}"
  end
end

.save_image(wrapper, destination, **options) ⇒ Object



42
43
44
# File 'lib/image_processing/pura.rb', line 42

def self.save_image(wrapper, destination, **options)
  ::Pura::Image::Processor.save(wrapper, destination.to_s, **options)
end

.supports_resize_on_load?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/image_processing/pura.rb', line 26

def self.supports_resize_on_load?
  false
end

Instance Method Details

#colourspace(space, **_options) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/image_processing/pura.rb', line 84

def colourspace(space, **_options)
  if %w[b-w grey16].include?(space.to_s)
    image.grayscale
  else
    image
  end
end

#convert(format, **_options) ⇒ Object



96
97
98
99
100
# File 'lib/image_processing/pura.rb', line 96

def convert(format, **_options)
  # Store desired format for save_image
  @format = format.to_s.delete(".")
  image
end

#crop(left, top, width, height, **_options) ⇒ Object



76
77
78
# File 'lib/image_processing/pura.rb', line 76

def crop(left, top, width, height, **_options)
  image.crop(left, top, width, height)
end

#resize_and_pad(width, height, background: nil, **_options) ⇒ Object



67
68
69
70
# File 'lib/image_processing/pura.rb', line 67

def resize_and_pad(width, height, background: nil, **_options)
  bg = background || [0, 0, 0]
  image.resize_and_pad(width, height, background: bg)
end

#resize_to_cover(width, height, **_options) ⇒ Object



72
73
74
# File 'lib/image_processing/pura.rb', line 72

def resize_to_cover(width, height, **_options)
  image.resize_to_cover(width, height)
end

#resize_to_fill(width, height, **_options) ⇒ Object



63
64
65
# File 'lib/image_processing/pura.rb', line 63

def resize_to_fill(width, height, **_options)
  image.resize_to_fill(width, height)
end

#resize_to_fit(width, height, **_options) ⇒ Object



57
58
59
60
61
# File 'lib/image_processing/pura.rb', line 57

def resize_to_fit(width, height, **_options)
  width ||= image.width
  height ||= image.height
  image.resize_to_fit(width, height)
end

#resize_to_limit(width, height, **_options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/image_processing/pura.rb', line 46

def resize_to_limit(width, height, **_options)
  w = image.width
  h = image.height

  return image if w <= (width || w) && h <= (height || h)

  width ||= w
  height ||= h
  image.resize_to_fit(width, height)
end

#rotate(degrees, **_options) ⇒ Object



80
81
82
# File 'lib/image_processing/pura.rb', line 80

def rotate(degrees, **_options)
  image.rotate(degrees)
end

#strip(**_options) ⇒ Object



92
93
94
# File 'lib/image_processing/pura.rb', line 92

def strip(**_options)
  image.strip
end