Module: ETFC::Image

Defined in:
lib/etfc/image.rb

Class Method Summary collapse

Class Method Details

.crop(image, width = 300, height = 300) ⇒ Object

Public: Crop an image destructively

image - path of the image that shall be cropped width - OPTIONAL width, defaults to 300 height - OPTIONAL height, defaults to 300

Examples:

crop('/abc/123.jpg')
#=> #<Magick::Image:70103481521220> => /abc/123.jpg JPEG
                    800x600=>300x300 800x600+250+150 DirectClass 8-bit

Returns Magick::Image with the crop transformation queued



39
40
41
42
43
# File 'lib/etfc/image.rb', line 39

def crop(image, width = 300, height = 300)
  img = Magick::Image.read(image)[0]
  img.crop!(Magick::CenterGravity, width, height)
  img.write(image)
end

.download(url, name) ⇒ Object

Public: Download a file and save it to the temporary folder

url - URL of the file that shall be downloaded name - name for the to be downloaded file

Examples:

download('http://example.com/abc.jpg', '123.jpg')
#=> "/var/tmp/111/222/123.jpg"

Returns String with the location of the downloaded file



19
20
21
22
23
24
# File 'lib/etfc/image.rb', line 19

def download(url, name)
  path = "#{ETFC::TMP_DIR}/#{name}"
  download = open(url)
  IO.copy_stream(download, path)
  path
end