简体   繁体   English

通过URL输入渲染/预览图像

[英]Render/ Preview Image from URL input

I'm looking for a solution to render image before uploading via input URL. 我正在寻找一种在通过输入URL上传之前渲染图像的解决方案。

在此处输入图片说明

My code 我的密码

<input name="thumbnail" placeholder="Post image URL here" />

I've been trying methods like this . 我一直在试图方法是这样 Adding onchange="readURL(this);" 添加onchange="readURL(this);" to above mentioned code does nothing. 上面提到的代码什么都不做。 It appears they only work with local files only. 看来它们仅适用于本地文件。

use the value of the input as the source for an image tag. 使用输入的值作为图像标签的来源。 You can hide and show the image tag, create a new image each time, wait for the load event and show a spinner, use a default image, the possibilities are endless. 您可以隐藏和显示image标签,每次创建一个新图像,等待load事件并显示一个微调框,使用默认图像,可能性是无穷的。

$('[name="thumbnail"]').on('change', function() {
     $('img.preview').prop('src', this.value);
});

FIDDLE 小提琴

You could use canvas. 您可以使用画布。

var oCanvas = doc.getElementById('imgThumb'),
    oContext = oCanvas.getContext('2d');

oContext.drawImage(this, 0, 0, nWidth, nHeight);

Try out my fiddle http://jsfiddle.net/aliasm2k/tAum2/ 试试我的小提琴http://jsfiddle.net/aliasm2k/tAum2/

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

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