最後,解決方案是客戶端。 這是關於上傳之前的圖像大小調整...沒有更多。 答案在上面的很多主題中已經存在。抱歉。 無論如何,這裏是代碼:
function readURL(input) {
if (input.files && input.files[0]) {
var current_file = input.files[0];
var reader = new FileReader();
reader.onload = function (event) {
var image = new Image();
image.src = event.target.result;
image.onload = function() {
var maxWidth = 500,
maxHeight = 500,
imageWidth = image.width,
imageHeight = image.height;
if (imageWidth > imageHeight) {
if (imageWidth > maxWidth) {
imageHeight *= maxWidth/imageWidth;
imageWidth = maxWidth;
}
}
else {
if (imageHeight > maxHeight) {
imageWidth *= maxHeight/imageHeight;
imageHeight = maxHeight;
}
}
var canvas = document.createElement('canvas');
canvas.width = imageWidth;
canvas.height = imageHeight;
image.width = imageWidth;
image.height = imageHeight;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
$('#example').attr('src', canvas.toDataURL(current_file.type));
}
}
reader.readAsDataURL(input.files[0]);
}
}
$("#inputfiles").change(function(){
readURL(this);
});
「meme generator」......呵呵。你是否也遇到了一個特定的錯誤,或者只是詢問一個關於你應該如何繼續的廣泛問題?如果您確實有錯誤,請嘗試縮小它發生的位置。 – Bloodied