有很多PHP调整大小的图像脚本,例如this one,但是我对PHP很新,需要帮助我使用JQuery / HTML5制作的特定格式;
$('#blah').attr('src', e.target.result);
width = $('#blah').width(); // Current image width
height = $('#blah').height(); // Current image height
if ( width > 119 && height > 119 ){
if (width > height) {
ratio = width / height; // get ratio for scaling image
newWidth = 120 * ratio;
margin = '-' + (newWidth - 120) /2 + 'px';
$('img#blah').css("width", newWidth + 'px'); // Set new width
$('img#blah').css("height", '120px'); // Scale height based on ratio
$('#blah').css("margin-left", margin);
}
if (height > width) {
ratio = height / width; // get ratio for scaling image
newHeight = 120 * ratio;
margin = '-' + (newHeight - 120) /2 + 'px';
$('img#blah').css("height", newHeight + 'px'); // Set new width
$('img#blah').css("width", '120px'); // Scale height based on ratio
$('#blah').css("margin-top", margin);
}
我已经制作了Fiddle here来显示我的完整脚本的工作结果。我现在正尝试将缩放的裁剪版本上传到我服务器上的特定目录。