你能用 Paperclip 识别图像的当前尺寸吗? [英] Can you identify the current dimensions of an image with Paperclip?

查看:64
本文介绍了你能用 Paperclip 识别图像的当前尺寸吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新了图像缩略图的尺寸,并且一直致力于更新 28,000 个照片对象.不幸的是,这种过程需要很长时间才能完成.在这个过程中,有的被拒绝,有的被取消.

I just updated the dimensions of an image thumbnail, and have been working on updating 28,000 photo objects. Unfortunately, this kind of process takes many processes over a long time to accomplish. In this process, some get rejected, and some processes get canceled.

有没有办法识别图像缩略图是否具有当前尺寸?

Is there a way to identify whether an image thumbnail has the current dimensions or not?

推荐答案

我不确定我是否理解您的问题,但您可以使用 Paperclip 获取任何文件的宽度和高度.

I'm unsure I understood your question but you can get the width and height of any file using Paperclip.

geo = Paperclip::Geometry.from_file(user.picture.path(:thumbnail))
geo.width
geo.height

您可以自动获取任何样式的尺寸:

You could get the dimensions of any style automatically:

user.picture.styles[:thumbnail].geometry # => "125x125!"

你甚至有一些有用的方法,比如:

You even have some useful methods like:

geo.horizontal?
geo.vertical?

这篇关于你能用 Paperclip 识别图像的当前尺寸吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆