Class: FastImage
- Inherits:
-
Object
- Object
- FastImage
- Defined in:
- lib/fastimage_resize.rb
Defined Under Namespace
Classes: FormatNotSupported
Constant Summary collapse
- SUPPORTED_FORMATS =
[:jpeg, :png, :gif]
Class Method Summary collapse
- .resize(uri_in, file_out, w, h, options = {}) ⇒ Object
- .resize_local(file_in, file_out, w, h, jpeg_quality) ⇒ Object
Instance Method Summary collapse
Class Method Details
.resize(uri_in, file_out, w, h, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fastimage_resize.rb', line 40 def self.resize(uri_in, file_out, w, h, ={}) jpeg_quality = [:jpeg_quality] || -1 u = URI.parse(uri_in) if u.scheme == "http" || u.scheme == "https" || u.scheme == "ftp" f = Tempfile.new(name) f.write(open(u).read) f.close resize_local(f.path, file_out, w, h, jpeg_quality) File.unlink(f.path) else resize_local(uri_in, file_out, w, h, jpeg_quality) end rescue OpenURI::HTTPError, SocketError raise ImageFetchFailure end |
.resize_local(file_in, file_out, w, h, jpeg_quality) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/fastimage_resize.rb', line 57 def self.resize_local(file_in, file_out, w, h, jpeg_quality) fi = new(file_in, :raise_on_failure=>true, :type_only=>true) type_index = SUPPORTED_FORMATS.index(fi.type) raise FormatNotSupported unless type_index fi.resize_image(file_in, file_out, w, h, type_index, jpeg_quality) end |
Instance Method Details
#resize_image(filename_in, filename_out, w, h, image_type, jpeg_quality) ⇒ Object
64 |
# File 'lib/fastimage_resize.rb', line 64 def resize_image(filename_in, filename_out, w, h, image_type, jpeg_quality); end |