Module: Vips::Process
- Included in:
- Base
- Defined in:
- lib/vips-process.rb,
lib/vips-process/base.rb,
lib/vips-process/crop.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, Crop, GaussianBlur, Quality, Resize, Strip Classes: Base
Constant Summary collapse
- JPEG =
'jpeg'.freeze
- PNG =
'png'.freeze
- VERSION =
"0.2.2"
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
- #sequential(val = true) ⇒ 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
89 90 91 |
# File 'lib/vips-process.rb', line 89 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#dst!(dst) ⇒ Object
Allow changing dst and chain it afterwards
50 51 52 53 |
# File 'lib/vips-process.rb', line 50 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.
20 21 22 23 24 25 26 |
# File 'lib/vips-process.rb', line 20 def manipulate! @_load_opts ||= {} @_on_process ||= [] @_type ||= jpeg? ? :jpeg : (png? ? :png : :new) @_vimage ||= VIPS::Image.send @_type, @src, @_load_opts @_vimage = yield @_vimage end |
#process! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vips-process.rb', line 28 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 |
#sequential(val = true) ⇒ Object
9 10 11 12 |
# File 'lib/vips-process.rb', line 9 def sequential(val=true) @_load_opts[:sequential] = val if jpeg? || png? self end |
#src!(src) ⇒ Object
Allow changing src and chain it afterwards
44 45 46 47 |
# File 'lib/vips-process.rb', line 44 def src!(src) @src = src self end |
#versions!(base = @dst) ⇒ Object
Process all versions using and output them in a directory
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vips-process.rb', line 59 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 |