简体   繁体   English

Rails回形针动态样式-避免缩放SVG

[英]Rails Paperclip dynamic styles - avoid scaling SVG

I want to provide my styles parameter with some lambda that checks if the file is an SVG file, scale it properly or not at all , I would like to communicate with the model as I do with all my other images, as when i render them (@image.image(:thumb). Is this possible? 我想为我的styles参数提供一些lambda值,以检查文件是否为SVG文件, 是否正确缩放或根本不缩放 ;我想与模型进行通信,就像处理所有其他图像一样,就像渲染它们时一样(@ image.image(:thumb)。这可能吗?

Right now I attach my file as: 现在,我将文件附加为:

has_mongoid_attached_file :image,
            :path => 'app/assets/images/library/:id/:style.:extension',
            :styles => {:thumb => "216x162#", :medium => "400x300#", :scenario => "700x525#"},
            :url => '/assets/library/:id/:style.:extension'

I've read about dynamic styles and did some trial and error with not success. 我已经阅读了有关动态样式的信息,并进行了一些反复尝试,但均未成功。 My thought was that someone perhaps already have done this. 我的想法是也许有人已经这样做了。

correct me if I misunderstood your question. 如果我误解了你的问题,请纠正我。

Please check https://github.com/thoughtbot/paperclip#dynamic-styles which says you can provide an lambda with attachment as argument of this lambda. 请检查https://github.com/thoughtbot/paperclip#dynamic-styles ,其中说您可以提供带有附件的lambda作为该lambda的参数。

Inside the block you can use attachment.instance.#{any instance method of model} . 在块内,您可以使用attachment.instance.#{any instance method of model}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM