RMagick无法读取远程图像 [英] RMagick can not read remote image

查看:99
本文介绍了RMagick无法读取远程图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  require'rubygems '
需要'RMagick'
Magick :: Image.read(http://image.domain.com/image.darenhui.com/images/random_bg/01.jpg)[0]

它会抛出如下错误:



<$ p $ 'read'中的p> :此图像格式没有解码委托`//image.domain.com/images/random_bg/01.jpg'@ error / construct.c / ReadImage / 532(Magick: :ImageMagickError),

但如果我从本地读取如下:

 要求'rubygems'
需要'RMagick'
Magick :: Image.read(/ local / staticimages / random_bg / 01.jpg )[0]

一切正常。
我运行识别-list格式,见下文:

  JPEG * JPEG rw-联合图像专家组JFIF格式( 62)
JPG * JPEG rw-联合图像专家组JFIF格式(62)

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



有人能给我一些线索吗?提前谢谢你。

解决方案

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


全部阅读来自指定文件的图像。


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



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


My env is Linux centos, and use ruby 1.8.7, and the code is here below:

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

it throws error like below:

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

but if i read from local like:

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

everything is ok. I run identify -list format and see below:

     JPEG* JPEG      rw-   Joint Photographic Experts Group JFIF format (62)
     JPG* JPEG      rw-   Joint Photographic Experts Group JFIF format (62)

but when i test by identity for "http://image.domain.com/image.darenhui.com/images/random_bg/01.jpg" to fail, but success for "/local/staticimages/random_bg/01.jpg"

Can someone give me some clue? thank you in advance.

解决方案

As far as I can see Magick::Image.read does NOT support URLs, only files/file handles - see http://www.imagemagick.org/RMagick/doc/image1.html#read where it says that it

Reads all the images from the specified file.

It is implemented by the C function ReadImage which does not support URLs - see the ImageMagick source at line 394 here.

IF you want to open an image from a URL you need to download the image somehow - to a file or a stream... then you can feed that file or stream to Magick...

这篇关于RMagick无法读取远程图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆