gpt4 book ai didi

imagemagick - RMagick 无法读取远程图像

转载 作者:行者123 更新时间:2023-12-03 17:10:59 25 4
gpt4 key购买 nike

我的环境是 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]

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

但如果我从本地读到:
    require 'rubygems'
require 'RMagick'
Magick::Image.read("/local/staticimages/random_bg/01.jpg")[0]

一切都好。
我运行识别 -list 格式,见下文:
     JPEG* JPEG      rw-   Joint Photographic Experts Group JFIF format (62)
JPG* JPEG rw- Joint Photographic Experts Group JFIF format (62)

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

有人可以给我一些线索吗?先感谢您。

最佳答案

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

关于imagemagick - RMagick 无法读取远程图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7264895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com