RMagick无法读取远程图像

ywe*_*nbo 12 rmagick imagemagick

我的env是Linux centos,并使用ruby 1.8.7,代码如下:

require 'rubygems'
require 'RMagick'
Magick::Image.read("http://image.domain.com/image.darenhui.com/images/random_bg/01.jpg")[0]
Run Code Online (Sandbox Code Playgroud)

它抛出如下错误:

in `read': no decode delegate for this image format `//image.domain.com/images/random_bg/01.jpg' @ error/constitute.c/ReadImage/532 (Magick::ImageMagickError), 
Run Code Online (Sandbox Code Playgroud)

但如果我从当地读到:

    require 'rubygems'
    require 'RMagick'
    Magick::Image.read("/local/staticimages/random_bg/01.jpg")[0]
Run Code Online (Sandbox Code Playgroud)

一切都好.我运行识别-list格式,见下文:

     JPEG* JPEG      rw-   Joint Photographic Experts Group JFIF format (62)
     JPG* JPEG      rw-   Joint Photographic Experts Group JFIF format (62)
Run Code Online (Sandbox Code Playgroud)

但是当我通过身份测试"http://image.domain.com/image.darenhui.com/images/random_bg/01.jpg"失败时,"/local/staticimages/random_bg/01.jpg"成功了

有人能给我一些线索吗?先感谢您.

小智 45

Magick::Image.read不支持URL链接.但是你可以使用ruby open方法读取远程图像:

 require 'rubygems'
 require 'RMagick'
 require "open-uri"


image = Magick::ImageList.new  
urlimage = open("http://www.jewelinfo4u.com/images/Gallery/ruby.jpg") # Image Remote URL 
image.from_blob(urlimage.read)

# crop = image.crop(10,10,200,300) You can crop this image too
# crop.write('C:/nameofyourNewImage.jpg') If you want to save the image you can use this line in windows 
Run Code Online (Sandbox Code Playgroud)


Pir*_*sko 6

快进到2014年5月,我能够......

require 'rubygems'
require 'RMagick'
include Magick
image = ImageList.new("http://www.jewelinfo4u.com/images/Gallery/ruby.jpg")
Run Code Online (Sandbox Code Playgroud)

它只是有效.感觉不错.

(在ImageMagick 6.8.8-9 Q16上测试)

编辑:虽然似乎没有Heroku Cedar堆栈(ImageMagick 6.5.7-8 2012-08-17 Q16).:/


Yah*_*hia 5

据我所知,Magick::Image.read不支持 URL,仅支持文件/文件句柄 - 请参阅http://www.imagemagick.org/RMagick/doc/image1.html#read那里说它

从指定文件中读取所有图像。

它由ReadImage不支持 URL的 C 函数实现- 请参阅此处第 394 行的 ImageMagick 源代码。

如果您想从 URL 打开图像,您需要以某种方式下载图像 - 到文件或流......然后您可以将该文件或流提供给 Magick...