ruby-on-rails – Carrierwave图像尺寸
发布时间:2020-12-17 04:38:32 所属栏目:百科 来源:网络整理
导读:如何获得当前载波实例的宽度和高度? 像这样的东西: car_images.each do | image| image_tag( image.photo_url,:width = image.photo_width,:height = image.photo_height)end 不幸的是,image.photo_width和image.photo_height无效. 我需要指定图像的宽度和
如何获得当前载波实例的宽度和高度?
像这样的东西: car_images.each do | image| image_tag( image.photo_url,:width => image.photo_width,:height => image.photo_height) end 不幸的是,image.photo_width和image.photo_height无效. 解决方法
结合
https://github.com/jnicklas/carrierwave/wiki/How-to:-Get-version-image-dimensions和
https://github.com/jnicklas/carrierwave/wiki/How-to:-Store-the-uploaded-file-size-and-content-type,你会得到:
class Image before_save :update_image_attributes private def update_image_attributes if image.present? self.content_type = image.file.content_type self.file_size = image.file.size self.width,self.height = `identify -format "%wx%h" #{image.file.path}`.split(/x/) # if you also need to store the original filename: # self.original_filename = image.file.filename end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 基于vue-ssr服务端渲染入门详解
- ReactNative源码篇:通信机制
- flex 多条件组合过滤函数
- 我的一个朋友过来面试引发我要说的一个小话题
- ruby-on-rails – Gem :: Installer :: ExtensionBuildErro
- c# – RowDataBound中的FindControl – 事件以错误结束
- PostgreSQL的监控一(pgsnap & pgstatspack)
- 第二章 深入探讨控制反转(Ioc)和依赖注入(DI)
- ajax+js+dom+json+php+mysql实现漂亮的表格各行变色与googl
- iphone – xcode在同一目标上的设备与模拟器的不同链接器/