调整图像大小并保持原始上传

Resize image and keep original on upload

本文关键字:原始 图像 调整      更新时间:2023-09-26

我正在使用blueimp的jQuery文件上传器,我想知道如何在上传时将图像调整为特定宽度,将其放入特定目录,同时保持原始图像。

到目前为止我写的是:

$('#fileupload').fileupload({
    dataType: 'json',
    add: function(e, data) {
        var uploadErrors = [];
        var acceptFileTypes = /^image'/(gif|jpe?g|png)$/i;
        if (data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
            uploadErrors.push('Invalid file type.');
        } else if (data.originalFiles[0]['size'] > 1000000) {
            uploadErrors.push('Image over size.');
        }
        if (uploadErrors.length > 0) {
            $('.errors').html(uploadErrors);
        } else {
            data.submit();
        }                    
    },
    progressall: function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('.progress .bar').css('width', progress + '%');
    }
});

您可以使用PHP-GD实现大小调整。

如果你谷歌一下,有几个参考文献。