要求RMagick向ImageMagick发送直接命令 [英] Ask RMagick to send a direct command to ImageMagick
问题描述
RMagick不支持ImageMagick的某些选项.同样有时候使用ImageMagick实际上更方便.是否有(图像对象的)方法可以让您使用命令行界面将命令直接发送到ImageMagick?
Some options of ImageMagick are not supported by RMagick. Also sometimes it is in fact more convenient to use ImageMagick. Is there a method (of the Image object) that allows you to send commands directly to ImageMagick using the command line interface?
推荐答案
您可以通过反引号(或类似符号)使用system
或系统调用吗?
Would it be ok for you to use system
or system call via backticks (or similar)?
您也可以扩展Magick::Image
使其更容易.
You may also extend Magick::Image
to do it easier.
我的示例代码添加了一种方法convert
,以调用imagemagick的convert-command来获取实际图像.必须添加要执行的操作.
My example code add a method convert
to call the convert-command of imagemagick for the actual image. The action to be performed must be added.
require 'rmagick'
module Magick
class Image
def convert( cmd )
`convert #{self.filename} #{cmd}`
end
end
end
picname = Dir['*.jpg'].first
img = Magick::Image.read(picname).first
img.convert('x.png')
这篇关于要求RMagick向ImageMagick发送直接命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!