Module: Pushfile::Resize

Included in:
Upload
Defined in:
lib/pushfile/resize.rb

Instance Method Summary collapse

Instance Method Details

#resize!Object

Resize file. Keeping aspect ratio.



7
8
9
10
11
12
13
14
15
16
# File 'lib/pushfile/resize.rb', line 7

def resize!
  begin
    image = MiniMagick::Image.open(@file.path)
    image.resize("#{@width}x#{@height}")
  rescue
    # Pass on any error
  else
    image.write(@file.path) rescue nil
  end
end

#thumbnail!Object

Create thumbnail, same name but with _thumb at the end



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pushfile/resize.rb', line 19

def thumbnail!
  begin
    image = MiniMagick::Image.open(@file.path)
    image.resize("#{Pushfile.settings[:images][:thumb][:width]}x")
  rescue
    @thumb = nil
  else
    t = @name.split('.'); ext = t.pop
    @thumb = t.join(".").concat("_thumb.#{ext}")
    image.write("/tmp/#{@thumb}") rescue @thumb = nil
  end
end