Sha256: 01f2f5d632fb1b01f31ff2f6a052cbe6211dcceca3cc97d82911639e732480f2
Contents?: true
Size: 927 Bytes
Versions: 12
Compression:
Stored size: 927 Bytes
Contents
#!/usr/bin/ruby $: << '../lib' require 'gearman' require 'optparse' require 'RMagick' Gearman::Util.debug = true servers = 'localhost:7003' opts = OptionParser.new opts.banner = "Usage: #{$0} [options]" opts.on('-s SERVERS', '--servers', 'Job servers, comma-separated host:port') { servers } opts.parse! worker = Gearman::Worker.new(servers.split(','), 'example') worker.add_ability('scale_image') do |data,job| width, height, format, data = data.split("\0", 4) width = width.to_f height = height.to_f image = Magick::Image.from_blob(data)[0] orig_ratio = image.columns.to_f / image.rows new_ratio = width / height w = new_ratio < orig_ratio ? width : orig_ratio / new_ratio * width h = new_ratio > orig_ratio ? height : new_ratio / orig_ratio * height puts "Got #{image.inspect}; resizing to #{w}x#{h} #{format}" image.resize!(w, h) image.format = format image.to_blob end loop { worker.work }
Version data entries
12 entries across 12 versions & 2 rubygems