如何“事后”用载波裁剪图像?在铁轨上?
我想做的是上传图像,然后将用户带到一个新页面,在该页面中我将使用 Jcrop 让用户选择他们想要裁剪的图像部分,然后存储该图像。本质上,我想让它成为一个两阶段的过程。
我知道如何执行 javascript 部分,并且了解如何创建此功能的基本流程。但是,我不知道如何实现这一点的载波细节。
我能找到的最接近的东西是:
image.recreate_versions!
但我仍然无法传递高度/宽度并开始 x,y 来裁剪它。
例如,我如何告诉 Carrierwave “事后”进行裁剪 - 即不是在第一次上传图像时进行裁剪?我看到“处理”图像的方法,但它们会以固定的高度和宽度自动发生。我怎样才能推迟这个呢?
本质上,我想做的是动态定义一个版本,我可以在其中指定高度、宽度以及 x,y
谢谢
What I'd like to do is upload an image, then take the user to a new page where I will use Jcrop to let the user select the part of the image they want to crop, and then store that image. Essentially, I want to make it a 2-stage process.
I know how to do the javascript part, and I understand the basic flow of how to create this functionality. However, I am not aware of the carrierwave specifics on how to accomplish this.
The closest thing I can find is:
image.recreate_versions!
But I still can't pass in the height/width and starting x,y to crop it.
For example, how can I tell carrierwave to do the cropping 'after the fact' - i.e. not when the image is uploaded for the first time? I see methods to "process" the image, but they happen automatically with fixed Height and Width. How can I delay this?
Essentially, what I'd like to do is define a version dynamically, where I can specify the height and width and x,y
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我能做的最好的了。可能有一种更简单的方法来做到这一点,但这是我的技巧:
这是传递裁剪信息时我的“POST”控制器操作:
这是添加到包含“头像”图像上传器的用户模型的方法:
基本上这只是劫持当前的,覆盖它,然后告诉 Carrierwave 创建
This is the best I can do. There's probably an easier way to do it, but this is my hack:
Here is my 'POST' controller action when the cropping info is passed:
Here is the method to add to the User model that contains an "avatar" image uploader:
Basically this just hi-jacks the current one, overwrites it, and then tells Carrierwave to create