问题描述
|
我是jQuery新手,但我喜欢它!香港专业教育学院有一个问题,我无法解决。
我正在使用http://www.zurb.com/playground/ajax_upload
我已经使用以下upload.PHP工作
<?
$time= time();
$uploaddir = \'users/\'; //<-- Changed this to my directory for storing images
$uploadfile = $uploaddir.$time.basename($_FILES[\'userfile\'][\'name\']); //<-- IMPORTANT
if (move_uploaded_file($_FILES[\'userfile\'][\'tmp_name\'],$uploadfile)) {
echo $uploaddir.$time.$_FILES[\'userfile\'][\'name\']; // IMPORTANT
#print_r($_FILES);
} else {
// WARNING! DO NOT USE \"FALSE\" STRING AS A RESPONSE!
// Otherwise onSubmit event will not be fired
echo \"error\";
}
?>
我添加了时间变量,以确保每个图像都是唯一的。我的问题是我想即时调整大小和优化图像,我不确定如何做到这一点。
调整大小是我需要的最重要的功能-例如,我希望保存的图像的最大宽度为300px,即使它最初的宽度为1000px。我需要按比例调整大小(这是一个字吗?:))
任何帮助都会很棒。
问候
中号
解决方法
要调整图像大小,您需要像GD这样的库
执行此操作的标准功能是GD \ imagecopy重新采样。
在示例中显示了一种调整大小和保持比例的方法:
//> MAx
$width = 200;
$height = 200;
// Get new dimensions
list($width_orig,$height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
,PHP,GD或Imagemagick中有两个主要的图像处理操作。两者都将能够满足您的需求。您将需要在PHP Web服务器上对其进行配置。