Can you identify the current dimensions of an image with Paperclip?

人走茶凉 提交于 2020-01-06 05:34:08

问题


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?


回答1:


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?


来源:https://stackoverflow.com/questions/6806801/can-you-identify-the-current-dimensions-of-an-image-with-paperclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!