### Querying pkg-config for vips information Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Commands to list all available pkg-config packages and get library information for vips. ```bash pkg-config --list-all |grep -i vips ``` ```bash pkg-config --libs vips ``` -------------------------------- ### Installing libvips to a custom directory Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Steps to configure, make, and install libvips to a specified prefix, typically in the user's home directory. ```bash ./configure --prefix=/home/john/vips make make install ``` -------------------------------- ### Installing full-fat vips with Homebrew Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Command to install vips using Homebrew with a comprehensive list of optional dependencies. ```bash brew install vips --with-cfitsio --with-fftw --with-imagemagick \ --with-libexif --with-liboil --with-libtiff --with-little-cms \ --with-openexr --with-openslide --with-pango ``` -------------------------------- ### Getting Homebrew vips info Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Command to display information about the vips package in Homebrew, including optional dependencies. ```bash brew info vips ``` -------------------------------- ### Installing vips using Homebrew Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Commands to tap the science repository and install the vips package using Homebrew on macOS. ```bash brew tap homebrew/science brew install vips ``` -------------------------------- ### filename method example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Connection.md Example usage of the filename method. ```ruby source = Vips::Source.new_from_file("image.jpg") puts source.filename # => "image.jpg" # Memory-based source returns nil source = Vips::Source.new_from_memory(buffer) puts source.filename # => nil ``` -------------------------------- ### Verifying vips installation on macOS Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Command to check the installed vips version. ```bash vips --version ``` -------------------------------- ### Version Compatibility Check Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Example of how to check if the installed libvips version meets a specific requirement. ```ruby Vips.at_least_libvips?(major, minor) ``` -------------------------------- ### nick method example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Connection.md Example usage of the nick method. ```ruby source = Vips::Source.new_from_file("image.jpg") puts source.nick # => "image.jpg" or similar source = Vips::Source.new_from_descriptor(0) puts source.nick # => "stdin" or similar target = Vips::Target.new_to_memory puts target.nick # => "memory" or similar ``` -------------------------------- ### Creating image of a specific colour Source: https://github.com/libvips/ruby-vips/wiki/Examples Example of creating a solid colored image with specific RGB values using ruby-vips. ```ruby value = [ 50, 100, 150 ] # RBG Values pixel = (Vips::Image.black(1, 1) + value).cast(:uint) image = pixel.embed 0, 0, 1200, 630, extend: :copy ``` -------------------------------- ### Example Usage Source: https://github.com/libvips/ruby-vips/blob/master/README.md A basic example demonstrating how to use the ruby-vips gem for image manipulation. ```ruby require "vips" im = Vips::Image.new_from_file filename # put im at position (100, 100) in a 3000 x 3000 pixel image, # make the other pixels in the image by mirroring im up / down / # left / right, see # https://www.libvips.org/API/current/method.Image.embed.html im = im.embed 100, 100, 3000, 3000, extend: :mirror # multiply the green (middle) band by 2, leave the other two alone im *= [1, 2, 1] # make an image from an array constant, convolve with it mask = Vips::Image.new_from_array [ [-1, -1, -1], [-1, 16, -1], [-1, -1, -1]], 8 im = im.conv mask, precision: :integer # finally, write the result back to a file on disk im.write_to_file output_filename ``` -------------------------------- ### Get supported file suffixes Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md Get a list of all image file suffixes supported by the installed libvips. ```ruby Vips.get_suffixes # => [String] ``` ```ruby supported = Vips.get_suffixes puts "Supported formats: #{supported.join(', ')}" ``` -------------------------------- ### Install on Linux and macOS Source: https://github.com/libvips/ruby-vips/blob/master/README.md Instructions for installing the ruby-vips gem on Linux and macOS. ```bash gem install ruby-vips ``` -------------------------------- ### Property Access Examples Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Object.md Demonstrates different ways to access object properties, including direct getter, generic get method, and accessing properties without direct getters. ```ruby # Direct property getter width = image.width # Generic get method width = image.get("width") # For properties that don't have direct getters value = image.get("some-property") ``` -------------------------------- ### Connect a Ruby block to a libvips signal. Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Object.md This example demonstrates connecting to the 'preeval' signal to print a message before evaluation starts, and to the 'eval' signal to print progress updates. ```ruby image.signal_connect("preeval") do |progress| puts "Starting computation" end image.signal_connect("eval") do |progress| puts "Progress: #{progress.percent}%" end ``` -------------------------------- ### Unsupported Format Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error when attempting to load an unsupported file format. ```ruby begin image = Vips::Image.new_from_file("image.xyz") rescue Vips::Error => e # Error: "Unable to find a loader for this format" end ``` -------------------------------- ### Removing custom libvips installation Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Command to easily remove a libvips installation made to a custom directory. ```bash rm -rf ~/vips ``` -------------------------------- ### Source/Target Errors Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error when unable to open a Source or Target. ```ruby begin source = Vips::Source.new_from_file("missing.jpg") rescue Vips::Error => e # Error: "No such file or directory" end ``` -------------------------------- ### Working with Gainmaps Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Example of updating the gainmap of an image. ```ruby gainmap = image.get_gainmap unless gainmap.nil? new_gainmap = gainmap.crop(left, top, width, height) image = image.mutate do |m| m.set_type!(Vips::IMAGE_TYPE, "gainmap", new_gainmap) end end ``` -------------------------------- ### File Loading Errors Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error when loading an invalid file. ```ruby begin image = Vips::Image.new_from_file("missing.jpg") rescue Vips::Error => e # Error: "Unable to open file for reading" end ``` -------------------------------- ### Setting environment variables for custom libvips installation Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Environment variables to set in .bashrc to use a libvips installation in a custom directory. ```bash export VIPSHOME=/home/john/vips export PATH=$VIPSHOME/bin:$PATH export LD_LIBRARY_PATH=$VIPSHOME/lib:$LD_LIBRARY_PATH export PKG_CONFIG_PATH=$VIPSHOME/lib/pkgconfig:$PKG_CONFIG_PATH ``` -------------------------------- ### Setting Metadata Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Example of setting metadata using MutableImage. ```ruby image = image.mutate do |m| m.set!("description", "My modified image") m.set!("author", "Jane Doe") end ``` -------------------------------- ### Thumbnail an image Source: https://github.com/libvips/ruby-vips/wiki/Examples Demonstrates how to create image thumbnails efficiently using the `thumbnail` operator, with options for processing from a file or a memory buffer. ```ruby #!/usr/bin/env ruby # batch-process a lot of files # # this should run in constant memory -- if it doesn't, something has broken require 'vips' # benchmark thumbnail via a memory buffer def via_memory(filename, thumbnail_width) data = IO.binread(filename) thumb = Vips::Image.thumbnail_buffer data, thumbnail_width, crop: 'centre' thumb.write_to_buffer '.jpg' end # benchmark thumbnail via files def via_files(filename, thumbnail_width) thumb = Vips::Image.thumbnail filename, thumbnail_width, crop: 'centre' thumb.write_to_buffer '.jpg' end ARGV.each do |filename| puts "processing #{filename} ..." thumb = via_memory(filename, 500) # thumb = via_files(filename, 500) end ``` -------------------------------- ### Global Configuration Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md Example of configuring ruby-vips for high-performance batch processing by setting concurrency, cache size, maximum memory, and enabling vector operations. ```ruby require "vips" # Configure for high-performance batch processing Vips.concurrency_set(Vips.concurrency_default) Vips.cache_set_max(2000) Vips.cache_set_max_mem(500 * 1024 * 1024) Vips.vector_set(true) # Process images... ``` -------------------------------- ### Compiling libvips on CentOS 5.5 Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Steps to download, extract, configure, make, and install libvips-7.28.8 on CentOS 5.5. ```bash wget -c http://www.vips.ecs.soton.ac.uk/supported/current/vips-7.28.8.tar.gz tar xzvf vips-7.28.8.tar.gz cd vips-7.28.8 ./configure && make && make install ``` -------------------------------- ### Annotate an image Source: https://github.com/libvips/ruby-vips/wiki/Examples Shows how to render text onto an image using the `text` operator and `ifthenelse` for blending. ```ruby #!/usr/bin/env ruby require 'vips' im = Vips::Image.new_from_file ARGV[0], access: :sequential left_text = Vips::Image.text "left corner", dpi: 300 left = left_text.embed 50, 50, im.width, 150 right_text = Vips::Image.text "right corner", dpi: 300 right = right_text.embed im.width - right_text.width - 50, 50, im.width, 150 footer = (left | right).ifthenelse(0, [255, 0, 0], blend: true) im = im.insert footer, 0, im.height, expand: true im.write_to_file ARGV[1] ``` -------------------------------- ### Compiling glib for older CentOS versions Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Steps to download, extract, configure, make, and install glib-2.21.6, required for libvips < 7.28.8 on CentOS 5. ```bash wget http://ftp.acc.umu.se/pub/gnome/sources/glib/2.21/glib-2.21.6.tar.gz tar zxvf glib-2.21.6.tar.gz cd glib-2.21.6/ ./configure make make install ``` -------------------------------- ### Get the GType of a property or metadata field. Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Object.md This example shows how to get the GType of the 'format' property and check if it exists. ```ruby gtype = image.get_typeof("format") if gtype == 0 puts "Property does not exist" end ``` -------------------------------- ### Incompatible Image Format Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error when an operation is incompatible with the image format. ```ruby begin # complex? requires complex format Vips::Image.complex?(image.format) unless image.is_a?(Vips::Image) && !Vips::Image.complex?(image.format) # Error condition triggered end rescue Vips::Error => e # Error: "not an even number of bands" end ``` -------------------------------- ### Get a property or metadata value from the object. Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Object.md This example demonstrates how to retrieve the 'width' and 'format' properties of an image object. ```ruby width = image.get("width") format = image.get("format") ``` -------------------------------- ### Setting PKG_CONFIG_PATH for ruby-vips on CentOS Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Environment variable export commands to resolve potential issues when installing the vips gem on CentOS. ```bash # To run 'gem install vips' once $ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig # or for constant use $ echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig" >> ~/.bash_profile ``` -------------------------------- ### Daltonize Source: https://github.com/libvips/ruby-vips/wiki/Examples Implementation of the daltonize algorithm for adjusting images to aid legibility for color-blind people, with explanations of color space conversions. ```ruby #!/usr/bin/ruby # daltonize an image with ruby-vips # based on # http://scien.stanford.edu/pages/labsite/2005/psych221/projects/05/ofidaner/colorblindness_project.htm # see # http://libvips.blogspot.co.uk/2013/05/daltonize-in-ruby-vips-carrierwave-and. # for a discussion of this code require 'vips' #Vips.set_debug true # matrices to convert D65 XYZ to and from bradford cone space xyz_to_brad = [ [0.8951, 0.2664, -0.1614], [-0.7502, 1.7135, 0.0367], [0.0389, -0.0685, 1.0296] ] brad_to_xyz = [ [0.987, -0.147, 0.16], [0.432, 0.5184, 0.0493], [-0.0085, 0.04, 0.968] ] im = Vips::Image.new_from_file ARGV[0] # remove any alpha channel before processing alpha = nil if im.bands == 4 alpha = im[3] im = im.extract_band 0, :n => 3 end begin # import to XYZ with lcms # if there's no profile there, we'll fall back to the thing below xyz = im.icc_import :embedded => true, :pcs => :xyz rescue Vips::Error # nope .. use the built-in converter instead xyz = im.colourspace :xyz end brad = xyz.recomb xyz_to_brad # through the Deuteranope matrix # we need rows to sum to 1 in Bradford space --- the matrix in the original # Python code sums to 1.742 deut = brad.recomb [ [1, 0, 0], [0.7, 0, 0.3], [0, 0, 1] ] xyz = deut.recomb brad_to_xyz # .. and back to sRGB rgb = xyz.colourspace :srgb # so this is the colour error err = im - rgb # add the error back to other channels to make a compensated image im = im + err.recomb([ [0, 0, 0], [0.7, 1, 0], [0.7, 0, 1] ]) # reattach any alpha we saved above if alpha im = im.bandjoin(alpha) end im.write_to_file ARGV[1] ``` -------------------------------- ### Adding and Removing Metadata Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Example of adding and removing metadata. ```ruby image = image.mutate do |m| # Remove EXIF data m.remove!("exif-data") # Add new metadata m.set_type!(GObject::GSTR_TYPE, "comment", "Processed image") end ``` -------------------------------- ### Drawing on Images Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Example of drawing lines and rectangles on an image. ```ruby image = image.mutate do |m| # Draw lines (0 ... 100).step(10) do |i| m.draw_line!(255, 0, i, 100, i) end # Draw a rectangle m.draw_rect!(128, 50, 50, 200, 200, fill: true) end ``` -------------------------------- ### Create a composite image Source: https://github.com/libvips/ruby-vips/wiki/Examples Code snippet for creating a composite image by overlaying one image onto another. ```ruby background = Vips::Image.new_from_file 'background.jpg' photo = Vips::Image.new_from_file('600.jpeg') ) out = back.composite photo, "over", x: 100, y: 100 out.jpegsave('out.jpg') ``` -------------------------------- ### Invalid Filename Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error when Image.new_from_file is called with a nil filename. ```ruby begin image = Vips::Image.new_from_file(nil) rescue Vips::Error => e # Error: "filename is nil" end ``` -------------------------------- ### Memory Allocation Failure Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error for a memory allocation failure when creating a very large image. ```ruby begin # Attempting to create a very large image image = Vips::Image.new_from_array(Array.new(1_000_000_000) { 0 }) rescue Vips::Error => e # Error: "malloc failure" end ``` -------------------------------- ### Verifying pkg-config with vips on macOS Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Command to test if pkg-config correctly identifies vips libraries and paths. ```bash pkg-config vips --libs ``` -------------------------------- ### VIPS_CONCURRENCY Environment Variable Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md Example of setting the VIPS_CONCURRENCY environment variable to control the default number of worker threads and then running a Ruby script. ```bash export VIPS_CONCURRENCY=4 ruby your_script.rb ``` -------------------------------- ### Configuring pkg-config for Homebrew vips on macOS Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Setting PKG_CONFIG_PATH in .profile to include Homebrew's vips and libxml2 locations for external builds. ```bash export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/opt/libxml2/lib/pkgconfig ``` -------------------------------- ### Operation Invocation Failure Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error when calling a non-existent operation. ```ruby begin Vips::Operation.call("nonexistent_op", [image]) rescue Vips::Error => e # Error: "Unknown operation" end ``` -------------------------------- ### Return Value Handling Examples Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Operation.md Shows how to handle different return types from operations, including single outputs, multiple outputs, and optional outputs. ```ruby # Single required output result = image.rotate(45) # Multiple required outputs result1, result2 = image.split_bands # Optional outputs as final hash min_val, opts = image.min(x: true, y: true) x = opts['x'] y = opts['y'] ``` -------------------------------- ### Error Handling Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Operation.md Demonstrates how to catch Vips::Error exceptions that are thrown when an operation fails. ```ruby begin result = Vips::Operation.call("jpegload", ["nonexistent.jpg"]) rescue Vips::Error => e puts "Operation failed: #{e.message}" end ``` -------------------------------- ### Explicit Error Message Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md An example of raising a Vips::Error with an explicit message. ```ruby raise Vips::Error, "filename is nil" ``` -------------------------------- ### Get the maximum number of operations to cache Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Get the maximum number of operations to cache. ```ruby Vips.cache_max # => Integer ``` -------------------------------- ### DEFAULT_CONCURRENCY Constant Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Example of accessing the DEFAULT_CONCURRENCY constant. ```ruby Vips::DEFAULT_CONCURRENCY # => Integer ``` -------------------------------- ### Implicit Error Message Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md An example of raising a Vips::Error where the message is implicitly fetched from the libvips error buffer. ```ruby # Error message pulled from vips_error_buffer() raise Vips::Error if loader.nil? ``` -------------------------------- ### Dynamic operation method example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Shows how to call libvips operations dynamically as methods on an Image object, including retrieving options. ```ruby image.operation_name(required_args, **options) ``` ```ruby result, options = image.min(x: true, y: true) x_pos = options['x'] y_pos = options['y'] ``` -------------------------------- ### Invalid Operation Arguments Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example demonstrating catching a Vips::Error when calling an operation with invalid argument types or values. ```ruby begin result = image.crop(-10, -10, 100, 100) # Invalid coordinates rescue Vips::Error => e # Error: "rect out of bounds" end ``` -------------------------------- ### Raising and Catching Errors Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Demonstrates how all ruby-vips operations raise Vips::Error on failure and how to catch them. ```ruby begin image = Vips::Image.new_from_file("nonexistent.jpg") rescue Vips::Error => e puts "Failed to load image: #{e.message}" end ``` -------------------------------- ### Configuration - Check version Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Checking if the installed libvips version meets a minimum requirement. ```ruby # Check version if Vips.at_least_libvips?(8, 10) # Use 8.10+ features end ``` -------------------------------- ### MAX_COORD Constant Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Example of accessing the MAX_COORD constant. ```ruby Vips::MAX_COORD # => 10000000 ``` -------------------------------- ### Common Patterns Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Examples demonstrating common ruby-vips operations including loading, processing, batching with memory efficiency, error handling, and configuration for batch processing. ```ruby # Load and process image = Vips::Image.new_from_file("input.jpg", access: :sequential) image = image.rotate(45).resize(0.5).sharpen image.write_to_file("output.jpg", Q: 90) # Batch with memory efficiency images = Dir["*.jpg"].map { |f| img = Vips::Image.new_from_file(f, access: :sequential) img = img.resize(0.1) img.write_to_buffer(".jpg[Q=70]") } # Try-catch begin image = Vips::Image.new_from_file(filename) rescue Vips::Error => e puts "Failed: #{e.message}" end # Configure for batch processing Vips.concurrency_set(Vips.concurrency_default) Vips.cache_set_max(2000) Vips.cache_set_max_mem(500 * 1024 * 1024) ``` -------------------------------- ### draw_line! Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Draw a line on the image. ```ruby image = image.mutate do |m| m.draw_line!(255, 10, 10, 100, 100) m.draw_line!([255, 0, 0], 20, 20, 150, 150) # RGB red end ``` -------------------------------- ### Sequential mode read example Source: https://github.com/libvips/ruby-vips/wiki/Basic-concepts Opens an image in sequential access mode to optimize for operations that only need to read pixels top-to-bottom. ```ruby a = Vips::Image.new_from_file filename, access: :sequential ``` -------------------------------- ### Operator overload example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Demonstrates the use of overloaded arithmetic and comparison operators for image manipulation. ```ruby result = image * 2 + [10, 20, 30] # Scale and offset mask = image < 128 # Boolean mask ``` -------------------------------- ### vips_error_buffer() Usage Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example of how to get the current error message from libvips. ```ruby Vips.vips_error_buffer # => String ``` -------------------------------- ### File-Based Connections Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Connection.md Example of using file-based connections for sources and targets. ```ruby # Source from file source = Vips::Source.new_from_file("input.jpg") puts "Loading from: #{source.filename}" # Target to file target = Vips::Target.new_to_file("output.jpg") puts "Saving to: #{target.filename}" ``` -------------------------------- ### PKG_CONFIG_PATH environment variable Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Setting the PKG_CONFIG_PATH environment variable to include common locations for pkg-config files. ```bash export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/X11/lib/pkgconfig ``` -------------------------------- ### Get the default libvips concurrency level Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Get the default libvips concurrency level (number of CPU cores or VIPS_CONCURRENCY env var). ```ruby Vips.concurrency_default # => Integer ``` ```ruby default = Vips.concurrency_default current = Vips.concurrency puts "Default: #{default}, Current: #{current}" ``` -------------------------------- ### nick method Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Connection.md Get a human-readable nickname or description of the connection. ```ruby connection.nick # => String ``` -------------------------------- ### draw_rect! Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Draw a rectangle on the image. ```ruby image = image.mutate do |m| m.draw_rect!(255, 10, 10, 100, 100, fill: true) end ``` -------------------------------- ### filename method Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Connection.md Get the filename associated with this connection, if any. ```ruby connection.filename # => String, nil ``` -------------------------------- ### Get the maximum number of files kept open in the operation cache Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Get the maximum number of files kept open in the operation cache. ```ruby Vips.cache_max_files # => Integer ``` -------------------------------- ### Method Missing Wrapping Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Operation.md Demonstrates the equivalence between calling an operation directly via Vips::Operation.call and using the automatically wrapped method on an Image object. ```ruby # These are equivalent: image.rotate(45) Vips::Operation.call("rotate", [image, 45]) ``` -------------------------------- ### Configuration - Concurrency Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Setting and getting the number of concurrent threads libvips can use. ```ruby # Concurrency Vips.concurrency_set(4) puts Vips.concurrency ``` -------------------------------- ### Get libvips Library Version Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Retrieves the libvips library version as a string. ```ruby Vips::LIBRARY_VERSION # => "8.14.2" ``` -------------------------------- ### Automatic Type Conversion Examples Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Operation.md Illustrates how Ruby types are automatically converted to libvips GValue types for operation arguments. ```ruby # Scalar becomes VipsArrayDouble image.linear(1.5, 0.5) # Array of numbers becomes VipsArrayDouble image.linear([1, 2, 3], [10, 20, 30]) # Integer becomes gint image.rotate(45) ``` -------------------------------- ### Descriptor-Based Connections Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Connection.md Example of using descriptor-based connections for reading from stdin and writing to stdout. ```ruby # Read from stdin stdin_source = Vips::Source.new_from_descriptor(0) image = Vips::Image.new_from_source(stdin_source) # Write to stdout stdout_target = Vips::Target.new_to_descriptor(1) image.write_to_target(stdout_target, ".jpg") ``` -------------------------------- ### set! Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Set a metadata field on the image. ```ruby image = image.mutate do |m| m.set!("exif-data", my_exif) end ``` -------------------------------- ### Resolving libvips.so.32 LoadError on CentOS Source: https://github.com/libvips/ruby-vips/wiki/Installation-on-various-platforms Commands to update the dynamic linker configuration to resolve 'libvips.so.32: cannot open shared object file' errors. ```bash echo "/usr/local/lib/" >> /etc/ld.so.conf.d/local.conf /sbin/ldconfig ``` -------------------------------- ### Vips::Interesting Usage Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Example of using the `:centre` interesting region for smartcrop. ```ruby result = image.smartcrop(width, height, interesting: :centre) ``` -------------------------------- ### tracked_mem() Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Get current memory allocation in bytes. ```ruby Vips.tracked_mem # => Integer (bytes) ``` -------------------------------- ### Interpretation Enum Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Describes how to interpret pixel values in an image. ```ruby interp = image.interpretation # => :srgb ``` -------------------------------- ### Coding Enum Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Specifies how pixels are coded in the image. ```ruby coding = image.coding # => :none ``` -------------------------------- ### Access Enum Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Controls how an image is accessed during processing. ```ruby image = Vips::Image.new_from_file("input.jpg", access: :sequential) ``` -------------------------------- ### GLib Logger Configuration Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Get or set the Ruby Logger instance used for GLib/libvips messages. ```ruby GLib.logger # => Logger GLib.logger = log # Set custom logger GLib.logger.level = Logger::DEBUG ``` ```ruby require "logger" # Log to file instead of stdout GLib.logger = Logger.new("vips.log") GLib.logger.level = Logger::DEBUG # Process image (will log debug messages) image = Vips::Image.new_from_file("input.jpg") ``` -------------------------------- ### Get Number of Open Files Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Retrieves the count of currently open file descriptors. ```ruby Vips.tracked_files # => Integer ``` -------------------------------- ### Get Image Format Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the band format of the image (e.g., :uchar, :float, :double). ```ruby image.format # => Symbol ``` -------------------------------- ### Get libvips library version Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md The version of the libvips library currently in use. ```ruby Vips::LIBRARY_VERSION # => String (e.g., "8.14.2") ``` ```ruby puts "Using libvips #{Vips::LIBRARY_VERSION}" ``` -------------------------------- ### Reading Exif data error Source: https://github.com/libvips/ruby-vips/wiki/Troubleshooting Example of an error encountered when trying to read Exif data, typically due to version mismatches between ruby-vips and libvips. ```ruby img = VIPS::Image.new("img.jpg") img.get("exif-ifd0-Orientation") VIPS::Error: VIPS error: vips_image_get: field "exif-ifd0-Orientation" not found ``` -------------------------------- ### Get peak memory usage Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md Get peak memory usage by libvips. ```ruby Vips.tracked_mem_highwater # => Integer (bytes) ``` ```ruby peak_mb = Vips.tracked_mem_highwater / 1024 / 1024 puts "Peak memory: #{peak_mb} MB" ``` -------------------------------- ### Primary Class: Image - Metadata Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Getting and checking metadata fields of an image. ```ruby # Metadata value = image.get("field-name") type = image.get_typeof("field-name") fields = image.get_fields ``` -------------------------------- ### Get current memory usage Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md Get current memory usage by libvips. ```ruby Vips.tracked_mem # => Integer (bytes) ``` ```ruby puts "Current libvips memory: #{Vips.tracked_mem / 1024 / 1024} MB" ``` -------------------------------- ### Get the maximum memory for the operation cache Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Get the maximum memory for the operation cache. ```ruby Vips.cache_max_mem # => Integer ``` -------------------------------- ### vips_error_freeze() / vips_error_thaw() Usage Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example of freezing and thawing error reporting, useful for optional operations. ```ruby Vips.vips_error_freeze # Perform operations without reporting errors Vips.vips_error_thaw ``` ```ruby Vips.vips_error_freeze saver = Vips.vips_foreign_find_save_target(filename) Vips.vips_error_thaw if saver.nil? # Use fallback method end ``` -------------------------------- ### new_from_descriptor Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Source.md Create a source from a file descriptor. ```ruby Vips::Source.new_from_descriptor(descriptor) ``` ```ruby # Load image from stdin source = Vips::Source.new_from_descriptor(0) image = Vips::Image.new_from_source(source) ``` -------------------------------- ### Get default worker thread pool size Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md Get the default worker thread pool size. ```ruby Vips.concurrency_default # => Integer ``` ```ruby default = Vips.concurrency_default puts "Default concurrency: #{default}" ``` -------------------------------- ### Get current libvips worker pool size Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Get the current libvips worker pool size. ```ruby Vips.concurrency # => Integer ``` ```ruby puts "Using #{Vips.concurrency} threads" ``` -------------------------------- ### new_from_file Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Source.md Create a source from a file path. ```ruby Vips::Source.new_from_file(filename) ``` ```ruby source = Vips::Source.new_from_file("image.jpg") image = Vips::Image.new_from_source(source) ``` -------------------------------- ### Libvips Library Initialization Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Ensures the libvips library is initialized upon ruby-vips loading, raising a fatal error if initialization fails. ```ruby if Vips.vips_init($0) != 0 throw Vips.get_error end ``` -------------------------------- ### Sources and Targets - Sources Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Creating image sources from files, descriptors, or memory. ```ruby # Sources source = Vips::Source.new_from_file("input.jpg") source = Vips::Source.new_from_descriptor(0) # stdin source = Vips::Source.new_from_memory(data) image = Vips::Image.new_from_source(source, options_string) ``` -------------------------------- ### Retry with Fallback Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Demonstrates how to retry an operation with a fallback if the initial loader fails. ```ruby loader = Vips.vips_foreign_find_load_buffer(data, data.bytesize) if loader.nil? # Try alternative approach Vips::Operation.call("magickload_buffer", [data]) end ``` -------------------------------- ### new_from_memory Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Source.md Create a source from a memory buffer. ```ruby Vips::Source.new_from_memory(data) ``` ```ruby buffer = File.read("image.jpg") source = Vips::Source.new_from_memory(buffer) image = Vips::Image.new_from_source(source) ``` -------------------------------- ### Find Operation Names Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Command to list all operations with their class hierarchy. ```bash vips -l # Lists all operations with class hierarchy ``` -------------------------------- ### Angle Enum Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Rotation angle. ```ruby result = image.rot(:d90) ``` -------------------------------- ### Operations - With options Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Calling libvips operations with specific options. ```ruby # With options result = image.conv(kernel, precision: :float) result = image.affine([2, 0, 0, 2], interpolate: Vips::Interpolate.new(:bicubic)) ``` -------------------------------- ### Direction Enum Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Direction or orientation. ```ruby result = image.flip(:horizontal) ``` -------------------------------- ### remove! Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Remove a metadata field from the image. ```ruby image = image.mutate do |m| m.remove!("exif-data") end ``` -------------------------------- ### Enable or disable SIMD and runtime compiler Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Enable or disable SIMD and runtime compiler. ```ruby Vips.vector_set(enabled) # => Boolean ``` ```ruby # Disable SIMD (safe but slower) Vips.vector_set(false) # Re-enable SIMD Vips.vector_set(true) ``` -------------------------------- ### new_from_file Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Load an image from a file on disk. ```ruby Vips::Image.new_from_file("input.jpg", access: :sequential) ``` -------------------------------- ### tracked_allocs() Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Get the number of active allocations. ```ruby Vips.tracked_allocs # => Integer ``` -------------------------------- ### image Method Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Get the underlying image object. ```ruby mutable.image # => Vips::Image ``` -------------------------------- ### vips_error_clear() Usage Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Example of how to clear the error buffer. ```ruby Vips.vips_error_clear ``` -------------------------------- ### new_to_file Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Target.md Create a target for writing to a file. ```ruby Vips::Target.new_to_file(filename) ``` ```ruby target = Vips::Target.new_to_file("output.jpg") image.write_to_target(target, ".jpg[Q=90]") ``` -------------------------------- ### Precision Enum Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Precision mode for operations. ```ruby result = image.conv(kernel, precision: :integer) ``` -------------------------------- ### set_type! Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/MutableImage.md Set a metadata field with explicit GType. ```ruby image = image.mutate do |m| m.set_type!(Vips::IMAGE_TYPE, "gainmap", gainmap_image) end ``` -------------------------------- ### Sources and Targets - Targets Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/INDEX.md Creating image targets for writing to files, descriptors, or memory. ```ruby # Targets target = Vips::Target.new_to_file("output.jpg") target = Vips::Target.new_to_descriptor(1) # stdout target = Vips::Target.new_to_memory image.write_to_target(target, format_string) buffer = target.get("blob") # For memory targets ``` -------------------------------- ### Get Image Offset Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the image offset in pixels. ```ruby image.xoffset # => Integer image.yoffset # => Integer ``` -------------------------------- ### Get Image Height Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the height of the image in pixels. ```ruby image.height # => Integer ``` -------------------------------- ### Get Image Width Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the width of the image in pixels. ```ruby image.width # => Integer ``` -------------------------------- ### tracked_mem_highwater() Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md Get peak memory allocation in bytes. ```ruby Vips.tracked_mem_highwater # => Integer (bytes) ``` -------------------------------- ### new_from_source Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Load an image from a Source object. ```ruby source = Vips::Source.new_from_file("image.jpg") image = Vips::Image.new_from_source(source, "") ``` -------------------------------- ### Enable or disable SIMD Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Vips-Module.md Enable or disable SIMD and runtime compiler. ```ruby Vips.vector_set(enabled) # => Boolean ``` ```ruby # Disable for safety Vips.vector_set(false) ``` -------------------------------- ### Memory-Constrained Environments Configuration Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Configuration settings for memory-constrained environments. ```ruby # Reduce cache sizes Vips.cache_set_max(100) Vips.cache_set_max_mem(10 * 1024 * 1024) # 10 MB # Use sequential access for large files image = Vips::Image.new_from_file("large.jpg", access: :sequential) ``` -------------------------------- ### Usage with Image Loaders Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Source.md Source objects are designed to be passed to `Image.new_from_source`. ```ruby source = Vips::Source.new_from_file("test.jpg") image = Vips::Image.new_from_source(source, "", shrink: 2) ``` ```ruby # String format image = Vips::Image.new_from_source(source, "shrink=2") # Hash format image = Vips::Image.new_from_source(source, "", shrink: 2) ``` -------------------------------- ### High-Performance Scenarios Configuration Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Configuration settings for high-performance scenarios. ```ruby # Use full concurrency Vips.concurrency_set(Vips.concurrency_default) ``` -------------------------------- ### Import Vips Module Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/README.md This imports the Vips module and makes all classes and enums available. ```ruby require "vips" ``` -------------------------------- ### Get Metadata Field Type Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the GType of a metadata field. ```ruby image.get_typeof(name) # => Integer (GType) ``` -------------------------------- ### Check if SIMD and runtime compilation are enabled Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/configuration.md Check if SIMD and runtime compilation are enabled. ```ruby Vips.vector? # => Boolean ``` ```ruby if Vips.vector? puts "Using SIMD instructions" else puts "SIMD disabled" end ``` -------------------------------- ### Get Metadata Field Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves a metadata field from the image by name. ```ruby image.get(name) ``` ```ruby profile = image.get("icc-profile-data") exif = image.get("exif-data") ``` -------------------------------- ### Get Image Filename Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the filename of the image if it was loaded from a file. ```ruby image.filename # => String ``` -------------------------------- ### Get Image Bands Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the number of bands (channels) in the image. ```ruby image.bands # => Integer ``` -------------------------------- ### BandFormat Enum Example Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/types.md Specifies the data type of each pixel band. ```ruby format = image.format # => :uchar ``` -------------------------------- ### Memory-Based Connections Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Connection.md Example of using memory-based connections for loading from and saving to memory. ```ruby # Load from memory data = File.read("image.jpg") source = Vips::Source.new_from_memory(data) image = Vips::Image.new_from_source(source) # Save to memory target = Vips::Target.new_to_memory image.write_to_target(target, ".jpg") buffer = target.get("blob") ``` -------------------------------- ### Get metadata fields Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the names of all metadata fields associated with an image. ```ruby image.get_fields # => [String] ``` -------------------------------- ### Basic Try-Catch Pattern Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/errors.md A fundamental error handling pattern using begin-rescue. ```ruby begin image = Vips::Image.new_from_file(filename) rescue Vips::Error => e puts "Error: #{e.message}" # Handle error end ``` -------------------------------- ### Get Image Size Source: https://github.com/libvips/ruby-vips/blob/master/_autodocs/api-reference/Image.md Retrieves the image dimensions as an array [width, height]. ```ruby image.size # => [Integer, Integer] ```