【问题标题】:Disable certain styles while saving image in paperclip在回形针中保存图像时禁用某些样式
【发布时间】:2016-05-19 20:05:59
【问题描述】:

我正在使用回形针保存图像(版本 3.5.1)和(rails 版本 3.2.21)。我在我的回形针模型中定义了各种样式

has_attached_file(:image, 
              :styles => { 
                            :logo => "300x2000>", 
                            :thumbnail => '100x100#',
                            :large => '1000x1000#',
                            :background => '2048x1024#'
                          })

对于某些图像,我不需要特定的样式,而对于某些图像,我希望使用回形针来处理所有图像。我只希望处理thumbnaillogo 样式的图像的配置文件类型示例,而对于画廊图像,我希望它处理所有图像(logothumbnaillargebackground) .是否有可能在 paeprclip 中实现这一点?

【问题讨论】:

    标签: ruby ruby-on-rails-3 image-processing imagemagick paperclip


    【解决方案1】:

    看看https://github.com/thoughtbot/paperclip#dynamic-styles

    class User < ActiveRecord::Base has_attached_file :avatar, styles: lambda { |attachment| { thumb: (attachment.instance.boss? ? "300x300>" : "100x100>") } } end

    【讨论】:

    • 我在我们的应用程序中到处重复使用这种常见的回形针模式。所以我不想改变它。我在很多地方都看到过 before_post_process 函数用于我们想要处理处理器映像的情况,但我不明白在我的情况下如何使用这个钩子。
    猜你喜欢
    • 2013-06-25
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多