Class: FlatironS3Uploader::ImageResizer

Inherits:
Object
  • Object
show all
Defined in:
lib/flatiron_s3_uploader/image_resizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ImageResizer

Returns a new instance of ImageResizer.



9
10
11
12
13
14
# File 'lib/flatiron_s3_uploader/image_resizer.rb', line 9

def initialize(path)
  raise FlatironS3Uploader::FileNotFoundError unless File.exist?(path)

  @path = path
  @image = MiniMagick::Image.open(path)
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



7
8
9
# File 'lib/flatiron_s3_uploader/image_resizer.rb', line 7

def image
  @image
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/flatiron_s3_uploader/image_resizer.rb', line 7

def path
  @path
end

Instance Method Details

#mime_typeObject



22
23
24
# File 'lib/flatiron_s3_uploader/image_resizer.rb', line 22

def mime_type
  image.mime_type
end

#resize(width: nil, height: nil) ⇒ Object



16
17
18
19
20
# File 'lib/flatiron_s3_uploader/image_resizer.rb', line 16

def resize(width: nil, height: nil)
  image.resize("#{width}x#{height}")
  image.write(output_path)
  output_path
end