Class: Abqari::ImagePipeline::ShellBackend
- Inherits:
-
Object
- Object
- Abqari::ImagePipeline::ShellBackend
- Defined in:
- lib/abqari/image_pipeline.rb
Overview
Shell-out to vips or magick CLI. Used when ruby-vips isn't
available — slower per invocation (~150–300 ms each) but works
without the FFI dep.
Instance Method Summary collapse
- #dimensions(src) ⇒ Object
-
#initialize(cli, strip:) ⇒ ShellBackend
constructor
A new instance of ShellBackend.
- #name ⇒ Object
- #thumbnail(src, dest, width, format, quality) ⇒ Object
Constructor Details
#initialize(cli, strip:) ⇒ ShellBackend
Returns a new instance of ShellBackend.
746 747 748 749 |
# File 'lib/abqari/image_pipeline.rb', line 746 def initialize(cli, strip:) @cli = cli # 'vips' or 'magick' @strip = strip end |
Instance Method Details
#dimensions(src) ⇒ Object
765 766 767 768 769 770 771 772 773 774 775 776 |
# File 'lib/abqari/image_pipeline.rb', line 765 def dimensions(src) case @cli when 'vips' w = `vipsheader -f width #{src.shellescape} 2>/dev/null`.strip.to_i h = `vipsheader -f height #{src.shellescape} 2>/dev/null`.strip.to_i [w, h] if w.positive? && h.positive? when 'magick' out = `magick identify -format "%w %h" #{src.shellescape} 2>/dev/null`.strip dims = out.split.map(&:to_i) dims.size == 2 && dims.all?(&:positive?) ? dims : nil end end |
#name ⇒ Object
751 752 753 |
# File 'lib/abqari/image_pipeline.rb', line 751 def name "shell-#{@cli}" end |
#thumbnail(src, dest, width, format, quality) ⇒ Object
755 756 757 758 759 760 761 762 763 |
# File 'lib/abqari/image_pipeline.rb', line 755 def thumbnail(src, dest, width, format, quality) cmd = case @cli when 'vips' then vips_cmd(src, dest, width, format, quality) when 'magick' then magick_cmd(src, dest, width, format, quality) end success = system(*cmd, out: File::NULL, err: File::NULL) raise "Image processing failed: #{cmd.shelljoin}" unless success end |