Module: Vips::Process
- Included in:
- Base
- Defined in:
- lib/vips-process.rb,
lib/vips-process/base.rb,
lib/vips-process/strip.rb,
lib/vips-process/resize.rb,
lib/vips-process/convert.rb,
lib/vips-process/quality.rb,
lib/vips-process/version.rb,
lib/vips-process/auto-orient.rb,
lib/vips-process/gaussian-blur.rb
Defined Under Namespace
Modules: AutoOrient, ClassMethods, Convert, GaussianBlur, Quality, Resize, Strip Classes: Base
Constant Summary collapse
- JPEG =
'jpeg'.freeze
- PNG =
'png'.freeze
- VERSION =
"0.1.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#dst!(dst) ⇒ Object
Allow changing dst and chain it afterwards.
-
#manipulate! ⇒ Object
Manipulate the image with Vips.
- #process! ⇒ Object
-
#src!(src) ⇒ Object
Allow changing src and chain it afterwards.
-
#versions!(base = @dst) ⇒ Object
Process all versions using and output them in a directory.
Class Method Details
.included(base) ⇒ Object
91 92 93 |
# File 'lib/vips-process.rb', line 91 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#dst!(dst) ⇒ Object
Allow changing dst and chain it afterwards
53 54 55 56 |
# File 'lib/vips-process.rb', line 53 def dst!(dst) @dst = dst self end |
#manipulate! ⇒ Object
Manipulate the image with Vips. Saving of the image is delayed until after all the process blocks have been called. Make sure you always return an VIPS::Image object from the block
This method yields VIPS::Image for further manipulation.
It also raises an Exception if the manipulation failed.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vips-process.rb', line 17 def manipulate! @_on_process ||= [] @_vimage ||= if jpeg? VIPS::Image.jpeg @src, sequential: true elsif png? VIPS::Image.png @src, sequential: true else VIPS::Image.new @src end @_vimage = yield @_vimage rescue => e raise Exception.new("Failed to manipulate file, maybe it is not a supported image? Original Error: #{e}") end |
#process! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vips-process.rb', line 31 def process! if @_vimage tmp_name = @dst.sub /(\.[[:alnum:]]+)$/i, '_tmp\1' writer = writer_class.send :new, @_vimage, @_format_opts @_on_process.each { |block| block.call writer } writer.write tmp_name FileUtils.mv tmp_name, @dst reset! @dst end end |
#src!(src) ⇒ Object
Allow changing src and chain it afterwards
47 48 49 50 |
# File 'lib/vips-process.rb', line 47 def src!(src) @src = src self end |
#versions!(base = @dst) ⇒ Object
Process all versions using and output them in a directory
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vips-process.rb', line 62 def versions!(base=@dst) base_dir, base_ext, base_filename = File.file?(base) ? [File.dirname(base), File.extname(base), "#{File.basename(base, File.extname(base))}-"] : [base, File.extname(@src), nil] FileUtils.mkdir_p base_dir unless File.directory?(base_dir) && File.exist?(base_dir) self.class.versions.map do |name| [name, send("#{name}_version", File.join(base_dir, "#{base_filename}#{name}#{base_ext}"))] end end |