image_sorcery icon indicating copy to clipboard operation
image_sorcery copied to clipboard

Support for +commands

Open tmaier opened this issue 12 years ago • 2 comments
trafficstars

ImageSorcery only supports -commands, but there are also some +commands, like +repage

  def convert_to_arguments(args)
    special_args = [:layer, :annotate]
    args.reject {|k, v| special_args.include?(k) }.map {|k, v| " -#{k} '#{v}'"}
  end

https://github.com/EricR/image_sorcery/blob/master/lib/image_sorcery.rb#L135-L138

I would suggest following convention: If an argument is a symbol, it is an ordinary -command. If it is a string, the user takes care of the prefix by himself.

Alternative: Convert Symbol to string, check if it has a prefix (+ or -). If not, add -

tmaier avatar Apr 01 '13 12:04 tmaier

+1. I needed to construct a command like:

convert -size 100x100 xc:none \
  image_a.png -geometry +0+0 -composite \
  image_b.png -geometry +10+20 -composite \
  output.png

This was possible through the current public interface, but only just. I was relying on the fact that the convert output filename isn't escaped to pass in arbitrary command strings.

Going into production like that seemed like a bad idea, and the rest of my usage of ImageSorcery in this instance was minimal, so I opted to drop the dependency and go straight to ImageMagick via Process.spawn in the calling code instead, which also prevents shell escaping issues.

willglynn avatar Nov 18 '13 15:11 willglynn

I monkey-patched it like this:

class ImageSorcery
  private
  def convert_to_arguments(args)
    special_args = [:layer, :annotate]
    args.reject {|k, v| special_args.include?(k) }.map {|k, v| " #{k.is_a?(Symbol) ? '-'+k.to_s : k } #{v==true ? '' : 39.chr+v.to_s+39.chr} "}
  end
end

A bit messy but works fine, and allows you to do

magick['+repage'] = true

systemed avatar Jun 01 '17 22:06 systemed