Module: FastImage::Resize
- Defined in:
- lib/fastimage/resize/version.rb,
lib/fastimage/resize.rb
Defined Under Namespace
Modules: ClassMethods Classes: FormatNotSupported
Constant Summary collapse
- VERSION =
"3.4.0"
- SUPPORTED_FORMATS =
[:jpeg, :png, :gif, :tiff]
- FILE_EXTENSIONS =
prefer jpg to jpeg as an extension
[:jpg, :png, :gif, :tiff]
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
35 36 37 |
# File 'lib/fastimage/resize.rb', line 35 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#resize(width, height, options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fastimage/resize.rb', line 65 def resize(width, height, = {}) jpeg_quality = [:jpeg_quality] || -1 file_out = [:outfile] type_index = SUPPORTED_FORMATS.index(type) raise FormatNotSupported unless type_index if !file_out temp_file = Tempfile.new(["fastimage-resize-", ".#{FILE_EXTENSIONS[type_index]}"]) temp_file.binmode file_out = temp_file.path else temp_file = nil end FastImage.native_resize(path, file_out.to_s, width.to_i, height.to_i, type_index, jpeg_quality.to_i, orientation) raise FastImage::ImageFetchFailure, 'Image could be created' unless File.exist?(file_out.to_s) temp_file rescue RuntimeError => e raise FastImage::ImageFetchFailure, e. end |