रेल 5, पेपरक्लिप 5 अद्यतन
इसके बजाय अब एक पुस्तकालय जोड़ने के लिए होने के
, तो आप सिर्फ बाहर ImageMagick's convert command करने के लिए सिस्टम पर कॉल अपने grayscale option उपयोग करने के लिए कर सकते हैं। आप धुंध या किसी अन्य छवि मैजिक विकल्पों के लिए भी ऐसा ही कर सकते हैं, लेकिन मुझे ग्रेस्केल में रूपांतरण के लिए ऐसा करने की आवश्यकता है।
अपने मॉडल में (ग्राहक एक लोगो है):
class Client < ApplicationRecord
has_attached_file :logo,
styles: { thumb: "243x243#", grayscale: "243x243#" }
# ensure it's an image
validates_attachment_content_type :logo, content_type: /\Aimage\/.*\z/
# optional, just for name and url to be required
validates :name, presence: true
validates :url, presence: true
after_save :convert_grayscale
def convert_grayscale
system "convert #{self.logo.path(:thumb)} -grayscale Rec709Luminance #{self.logo.path(:grayscale)}"
end
def logo_attached?
self.logo.file?
end
end
तो बस (Paperclips github docs प्रति) इस तरह ध्यान में रखते हुए का उपयोग करें।
आपके विचार में:
<%= image_tag(client.logo.url(:grayscale), class: 'thumbnail', alt: client.name, title: client.name) %>
या एक लिंक यदि आप पसंद के साथ: महान उत्तर के लिए
<%= link_to(image_tag(client.logo.url(:grayscale), class: 'thumbnail', alt: client.name, title: client.name), client.url) %>
देरी के लिए खेद है, धन्यवाद! – jyoseph
अच्छी तरह से लगता है कि कन्वर्ट विकल्प ': शैलियों => {: ग्रे =>" 450x250 "} में परिवर्तित करना आसान है,: convert_options => {: gray =>" -blur 0x8 "}' – Ben