简体   繁体   English

如何在上传之前裁剪用户的图像/预览图像?

[英]How to crop image/ Preview Image from user before uploading it?

I want to make user upload his picture.我想让用户上传他的照片。

After he selects the picture from his local computer, my ultimate aim is to save thumbnails of that image of some specific sizes(rectangular).在他从他的本地计算机中选择图片后,我的最终目标是保存某些特定尺寸(矩形)的图像缩略图。 To maintain aspect ratio I have to prompt user to crop that image and then I will create thumbnails for it.为了保持纵横比,我必须提示用户裁剪该图像,然后我将为它创建缩略图。

For this I thought of way to First upload and then preview the image to the user为此,我想到了先上传然后向用户预览图像的方法
and then I would use external plugin(jcrop i guess) to crop that image然后我会使用外部插件(我猜是 jcrop)来裁剪该图像
and then finally send it to server.然后最后将其发送到服务器。

I am having trouble previewing the image.我在预览图像时遇到问题。 Some sources suggests like.一些消息来源表明喜欢。

<input type="file" onclick="preview(this)" >

with JS :与 JS :

function preview()
{
 alert(this.value);
 //code to append the image content in some div.
}

but I am only able to see final image name of the file in alert box(eg abc.jpg), not the entire path( eg /home/blah/blah .. /abc.jpg)但我只能在警报框中看到文件的最终图像名称(例如 abc.jpg),而不是整个路径(例如 /home/blah/blah .. /abc.jpg)

Is there any way I can make the user preview the image , so that i can crop it and then send to server?有什么办法可以让用户预览图像,以便我可以裁剪它然后发送到服务器? or do i have to save the original file first to the server and then only show user tool to crop the recently added image by him.还是我必须先将原始文件保存到服务器,然后才显示用户工具来裁剪他最近添加的图像。

What your are trying to archive is not really possible: Grapping an image from an user's local machine using JavaScript.您尝试存档的内容实际上是不可能的:使用 JavaScript 从用户的本地机器抓取图像。 (What a security issue). (多么安全的问题)。

But In some browsers (only thinks it's chrome) you can use this method: http://html5demos.com/file-api-simple但是在某些浏览器中(只认为它是 chrome),您可以使用这种方法: http : //html5demos.com/file-api-simple

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

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