ruby-vipsメモ

VIPS::Imageのメソッド

グレーアウトしているのはObjectクラスのMethods。

pry(main)> VIPS::Image.new("image.jpg").methods.sort
=> [:!, :!=, :!~, :%, :&, :*, :**, :+, :-, :/, :<<, :<=>, :==, :===, :=~, :>>, :[], :^, 
 :__binding__, :__id__, :__send__, 
 :abs, :acos, :add, :addgnoise, :affinei, :affinei_resize, :align_bands, :and, :asin, :atan, :avg, 
 :band_fmt, :bandjoin, :bandmean, :bands, :blend, 
 :c2amph, :c2imag, :c2real, :c2rect, :ceil, :class, :clip2fmt, :clone, :cntlines_h, :cntlines_v, :coding, :compass, :contrast_surface, :conv, :convsep, :copy_file, :copy_native, :copy_swap, :correl, :cos, :cross_phase, :csv, 
 :data, :de00_from_lab, :de_from_lab, :de_from_xyz, :decmc_from_lab, :define_singleton_method, :deviate, :dilate, :disp_ps, :display, :divide, :dup, 
 :each_pixel, :embed, :enum_for, :eql?, :equal, :equal?, :erode, :exif, :exif?, :expn, :extend, :extract_area, :extract_band, 
 :falsecolour, :fastcor, :filename, :fliphor, :flipver, :float_to_rad, :floor, :freeze, :freqflt, :frozen?, :fwfft, 
 :gammacorrect, :get, :global_balance, :global_balancef, :grad_x, :grad_y, :gradcor, :gradient, :grid, 
 :hash, :heq, :hist, :hist_indexed, :histcum, :histeq, :histgr, :histnd, :histnorm, :histplot, :histspec, :hsp, 
 :icc, :icc?, :icc_ac2rc, :icc_export_depth, :icc_import, :icc_import_embedded, :icc_transform, :ifthenelse, :im_lab_morph, :initialize_clone, :initialize_dup, :insert, :insert_noexpand, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_variable_defined?, :instance_variable_get, :instance_variable_set, :instance_variables, :invert, :invfft, :invfftr, :is_a?, 
 :jpeg, 
 :kill, :kind_of?, 
 :lab_to_labq, :lab_to_labs, :lab_to_lch, :lab_to_ucs, :lab_to_xyz, :lab_to_xyz_temp, :label_regions, :labq_to_lab, :labq_to_labs, :labq_to_xyz, :labs_to_lab, :labs_to_labq, :lch_to_lab, :lch_to_ucs, :less, :lesseq, :lhisteq, :lin, :lindetect, :log, :log10, :lrjoin, :lrmerge, :lrmerge1, :lrmosaic, :lrmosaic1, 
 :maplut, :match_linear, :match_linear_search, :max, :maxpos, :maxpos_avg, :maxpos_subpel, :maxvalue, :measure_area, :method, :methods, :min, :minpos, :monotonic?, :more, :moreeq, :mpercent, :mpercent_hist, :msb, :multiply, 
 :n_elements, :nil?, :notequal, 
 :object_id, :or, 
 :phasecor_fft, :png, :point, :pow, :ppm, :pretty_inspect, :pretty_print, :pretty_print_cycle, :pretty_print_inspect, :pretty_print_instance_variables, :private_methods, :profile_h, :profile_v, :project, :protected_methods, :pry, :public_method, :public_methods, :public_send, 
 :rad_to_float, :rank, :rank_image, :recomb, :remainder, :replicate, :respond_to?, :respond_to_missing?, :ri2c, :rightshift_size, :rint, :rot180, :rot270, :rot90, :rotquad, 
 :scale, :scaleps, :send, :set, :sharpen, :shrink, :sign, :sin, :singleton_class,:singleton_methods, :sizeof_element, :sizeof_line, :sizeof_pel, :spcor, :srgb_to_xyz, :stats, :stdif, :stretch3, :subsample, :subtract, 
 :taint, :tainted?, :tan, :tap, :tbjoin, :tbmerge, :tbmerge1, :tbmosaic, :tbmosaic1, :tiff, :tile_cache, :to_enum, :to_mask, :to_s, :tone_analyse, :trust, 
 :ucs_to_lab, :ucs_to_lch, :ucs_to_xyz, :untaint, :untrust, :untrusted?, 
 :vips, :vtype, 
 :wrap, :write, 
 :x_offset, :x_res, :x_size, :xor, :xyz_to_lab, :xyz_to_lab_temp, :xyz_to_srgb, :xyz_to_ucs, :xyz_to_yxy, 
 :y_offset, :y_res, :y_size, :yxy_to_xyz, 
 :zerox_neg, :zerox_pos, :zoom, :|]

VIPS::Imageで切り抜き

画像image.jpgの左上を原点として(x, y)を左上とする幅w, 高さhの長方形を切り抜いてimage_crop.jpgとして保存

VIPS::Image.new("image.jpg").extract_area(x, y, w, h).write("image_crop.jpg")

VIPS::Imageで拡大縮小(縦横別比率での拡大縮小も可能)

自由倍率

画像image.jpgをp倍にしてimage_magnify.jpgとして保存
(interpolator = :bilinear, :bicubic, :nearest... ref: http://www.vips.ecs.soton.ac.uk/index.php?title=Interpolation_samples)

VIPS::Image.new("image.jpg").affinei_resize(:bilinear, p).write("image_magnify.jpg")
VIPS::Image.new("image.jpg").affinei_resize(:bicubic, p).write("image_magnify.jpg")
VIPS::Image.new("image.jpg").affinei_resize(:nearest, p).write("image_magnify.jpg")

画像image.jpgを1/p倍にしてimage_shrink.jpgとして保存
アンチエイリアシングなし)

VIPS::Image.new("image.jpg").shrink(p).write("image_shrink.jpg")
整数倍率

画像image.jpgをi倍(i: 整数)すなわちiビット繰り返してimage_magnify.jpgとして保存

VIPS::Image.new("image.jpg").zoom(i).write("image_magnify.jpg") 

画像image.jpgを1/i倍(i: 整数)すなわちiビット毎にリサンプルしてimage_shrink.jpgとして保存

VIPS::Image.new("image.jpg").subsample(i).write("image_shrink.jpg")