Rails 5.2 ActiveStorage save and then read Exif data

99封情书 提交于 2019-12-01 21:11:53

I think you want to use a variant when displaying the image rather than trying to edit the stored image. To fix the orientation, you could say:

user.avatar.variant(auto_orient: true)

And if you want to do several operations at once (rather than in a pipeline), use combine_options:

user.avatar.variant(combine_options: {
  auto_orient: true,
  gravity:     'center',
  resize:      '23x42',    # Using real dimensions of course.
  crop:        '23x42+0+0'
})

The edited image will be cached so you only do the transformation work on first access. You might want to put your variants into view helpers (or maybe even a model concern depending on your needs) so that you can isolate the noise.

You might want to refer to the API docs as well as the guide:

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