gpt4 book ai didi

ruby-on-rails - Rails 回形针图像保存

转载 作者:行者123 更新时间:2023-12-02 02:21:09 25 4
gpt4 key购买 nike

使用回形针时,如果我尝试像这样输入网址(在图片保存后的创建功能中)

image = Magick::ImageList.new('public' + @picture.photo.url)

我得到了错误
Magick::ImageMagickError in PicturesController#create

no decode delegate for this image format `public/system/photos/115/original/Kitchener-2011103100531.jpg?1321026621' @ error/constitute.c/ReadImage/532

如果我尝试输入
@picture.latitude = EXIFR::JPEG.new('public' + @picture.photo.url).gps_lat

只处理我得到的 exif 数据
Errno::ENOENT in PicturesController#create

No such file or directory - public/system/photos/116/original/Kitchener-20111031-00531.jpg?1321026744

当我尝试在 rails 控制台中执行 photo.url 时,它提供了良好的格式,但在我的 Controller 中,最后添加了一些奇怪的垃圾 '?1321026621'。我该如何解决? (正则表达式看起来很容易解决这个问题,但有没有比这更好的方法)

最佳答案

来自 paperclip github project :

https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb

# Returns the public URL of the attachment with a given style. This does
# not necessarily need to point to a file that your Web server can access
# and can instead point to an action in your app, for example for fine grained
# security; this has a serious performance tradeoff.
#
# Options:
#
# +timestamp+ - Add a timestamp to the end of the URL. Default: true.
# +escape+ - Perform URI escaping to the URL. Default: true.
#
# Global controls (set on has_attached_file):
#
# +interpolator+ - The object that fills in a URL pattern's variables.
# +default_url+ - The image to show when the attachment has no image.
# +url+ - The URL for a saved image.
# +url_generator+ - The object that generates a URL. Default: Paperclip::UrlGenerator.
#
# As mentioned just above, the object that generates this URL can be passed
# in, for finer control. This object must respond to two methods:
#
# +#new(Paperclip::Attachment, Paperclip::Options)+
# +#for(style_name, options_hash)+
def url(style_name = default_style, options = {})
default_options = {:timestamp => @options.use_timestamp, :escape => true}

if options == true || options == false # Backwards compatibility.
@url_generator.for(style_name, default_options.merge(:timestamp => options))
else
@url_generator.for(style_name, default_options.merge(options))
end
end

默认情况下,回形针会附加一个时间戳参数,传递 :timestamp => falseurl你的附件方法:
image = Magick::ImageList.new('public' + @picture.photo.url(:original, :timestamp => false))

# => "public/system/photos/115/original/Kitchener-2011103100531.jpg"

编辑:实际上,看起来他们更改了选项名称,因为这对 Paperclip 2.4.0 不起作用。检查我自己的来源后,选项是 :use_timestamp但在 github 上是 :timestamp - 根据您使用的 Paperclip 版本选择哪一个。

关于ruby-on-rails - Rails 回形针图像保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8096582/

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