Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMagick can not read remote image

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.

like image 859
ywenbo Avatar asked Sep 01 '11 00:09

ywenbo


1 Answers

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...

like image 108
Yahia Avatar answered Sep 28 '22 03:09

Yahia