简体   繁体   English

如何在不保存原始图像的情况下保存图像URL的裁剪图像? (在使用Paperclip或其他插件的Rails中)

[英]How to save cropped image of an image URL without saving the original image? (in Rails using Paperclip or other plug-ins)

Hi all 大家好
I have an app now showing photos from URL, not from my own database (file system). 我现在有一个应用程序显示来自URL的照片,而不是来自我自己的数据库(文件系统)的照片。 For example, a photo from Facebook: 例如,来自Facebook的照片:
http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs085.snc1/5041_98423808305_40796308305_1960517_6704612_n.jpg http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs085.snc1/5041_98423808305_40796308305_1960517_6704612_n.jpg

I've added the crop function to get the cropping area (x,y,w,h) of the photo. 我添加了裁切功能以获取照片的裁切区域(x,y,w,h)。
And now I'd like to save the cropped image from the URL (ie without downloading the original image to my database before cropping) 现在,我想从URL中保存裁剪的图像(即在裁剪之前将原始图像下载到我的数据库中)

Is it even possible? 可能吗?
Or is there anyway to get the image into memory to process without saving it to database? 还是有某种方法可以将图像保存到内存中以进行处理而不保存到数据库中?
I've searched some questions here, but they all talk about how to save the crop of images which have been uploaded to the database by users. 我在这里搜索了一些问题,但是它们都讨论了如何保存用户已上传到数据库中的大量图像。

Thank you very much in advance. 提前非常感谢您。

How do you imagine cropping works without access to the original image? 您如何想象没有访问原始图像的裁剪效果? The process would be like this: 该过程将是这样的:

  1. Download the remote image to a /tmp as a temporary file (Tip: TempFile ) 将远程映像作为临时文件下载到/ tmp(提示: TempFile
  2. Crop the crap out of it 剪掉废话
  3. Save the cropped image with Paperclip to your DB 使用Paperclip将裁剪的图像保存到数据库
  4. Remove the temporary file 删除临时文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM