要求 RMagick 向 ImageMagick 发送直接命令

发布于 2025-01-07 12:11:08 字数 108 浏览 4 评论 0原文

RMagick 不支持 ImageMagick 的某些选项。有时使用 ImageMagick 实际上更方便。是否有(Image 对象的)方法允许您使用命令行界面直接向 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼中杀气 2025-01-14 12:11:08

您可以使用 system 或通过反引号(或类似的)进行系统调用吗?

您还可以扩展 Magick::Image 以使其更容易。

我的示例代码添加了一个方法 convert 来调用实际图像的 imagemagick 的转换命令。必须添加要执行的操作。

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')

Would it be ok for you to use system or system call via backticks (or similar)?

You may also extend Magick::Image to do it easier.

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')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文