我们可以使用 jquery 调整图像大小吗?

Can we resize image using jquery?

是否可以从 url 下载图像并使用 jquery 物理调整图像大小而不使用任何服务器端脚本? 我进行了大量搜索,但没有找到任何解决方案。

如果您需要下载,您可以使用 canvas 像这样

html

<canvas id="c" width="200" height="150"></canvas>
<a id="download">Download as image</a>

javascript

// Grab the Canvas and Drawing Context
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
// Create an image element
var img = document.createElement('IMG');
// Specify the src to load the image
img.setAttribute('crossOrigin', 'anonymous');
img.src = "http://i.imgur.com/adB2oag.png";
// When the image is loaded, draw it
img.onload = function () {
    ctx.drawImage(img, 0, 0, img.width,    img.height, 0, 0, canvas.width, canvas.height );
}

function downloadCanvas(link, canvasId, filename) {
    link.href = document.getElementById(canvasId).toDataURL();
    link.download = filename;
}

document.getElementById('download').addEventListener('click', function() {
    downloadCanvas(this, 'c', 'test.png');
}, false);

将图片放入 canvas 并根据需要调整图片大小,然后将 canvas 下载为图片

你可以试试这个jsFiddle