Attachment_fu:如何有选择地阻止缩略图创建?

发布于 2024-08-16 22:40:31 字数 746 浏览 5 评论 0原文

我很高兴使用 Attachment_fu 来处理文件上传和缩略图创建。但是,对于某些(但不是全部!)情况,我想禁止创建缩略图。

我如何破解 Attachment_fu 来做到这一点?

具体细节:我有一个传统的attachment_fu模型

class Pic < ActiveRecord::Base
  has_attachment :content_type => :image, :storage => :s3, :resize_to => '200x600>',
                 :thumbnails => { :thumb48 => [48,48], 
                                  :thumb32 => [32,32], 
                                  :thumb22 => [22,22] }
  validates_as_attachment
end

用户使用文件输入指定要在表单中上传的文件,并将表单提交到使用创建图片的操作

@pic = Pic.new(params[:pic])

在某些情况下我希望能够做一些事情喜欢

@pic = Pic.new(params[:pic], {:generate_thumbnails => false})

并阻止生成缩略图。

I'm happily using attachment_fu to handle file uploads and thumbnail creation. However, for some (but not all!) cases I would like to suppress the creation of thumbnails.

How would I hack attachment_fu to do this?

Specifics: I have a traditional attachment_fu model

class Pic < ActiveRecord::Base
  has_attachment :content_type => :image, :storage => :s3, :resize_to => '200x600>',
                 :thumbnails => { :thumb48 => [48,48], 
                                  :thumb32 => [32,32], 
                                  :thumb22 => [22,22] }
  validates_as_attachment
end

The user specifies the file to be uploaded in a form using a file input, and submits the form to an action where the pic is created using

@pic = Pic.new(params[:pic])

In certain cases I'd like to be able to do something like

@pic = Pic.new(params[:pic], {:generate_thumbnails => false})

and prevent the thumbnails from being generated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮倦 2024-08-23 22:40:31

有趣的问题。

您是否考虑过不显示某些图片的缩略图?或者存储是一个问题?

另一种选择是创建两个模型 - 一个称为 Pic,它不定义任何缩略图,然后一个称为 PicWithThumbs,它扩展了 Pic 类,并定义了缩略图。

然后在你的控制器中,你可以执行一个“if”语句来检查参数中是否有一个名为“create_thumbs”(布尔值)的值 - 如果 :create_thumbs 为 true,则创建一个 PicWithThumb 实例,否则创建一个 Pic

我知道,它闻起来像一点点,而且我有点菜鸟,所以请随意射杀我。我有兴趣看看最好的解决方案是什么......

interesting question.

have you thought about just not displaying the thumbnails for certain pics? or is storage a concern?

another option would be to create two models - one called Pic which doesn't define any thumbnails and then one called PicWithThumbs, which extends the Pic class, and does define thumbnails.

Then in your controller you could do an 'if' statement that checked the params for a value called 'create_thumbs' (boolean) - if :create_thumbs is true, then create an instance of PicWithThumb, else create a Pic

I know, it smells a little, and I'm a bit of a noob, so feel free to shoot me down. I'm interested in seeing what the best solution is though...

埋葬我深情 2024-08-23 22:40:31

我不确定附件 fu,但在 paperclip 中,您可以通过在 < 中返回 false 来停止缩略图生成code>before_post_process,在附件中,也许您可​​以在 process_attachment 回调中执行类似的操作?

I'm not sure about attachment fu, but in paperclip you can stop thumbnail generation by returning false in before_post_process, in attachment fu perhaps you could do a similar thing in the process_attachment callback?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文