如果您需要在运行时设置转换器,您需要设置两个额外的 aurigma 上传器事件:1.BeforeUpload 和 2.BeforePackageUpload:
uploader = new Uploader('Uploader1');
...
$uploader->getClientEvents()->setBeforeUpload("BeforeUpload");
$uploader->getClientEvents()->setBeforePackageUpload("BeforePackageUpload");
...
然后在 Javascript 块中实现事件代码(脚本类型 = “text/javascript”)。
您将需要获取添加到上传窗格的所有图像的宽度和高度,并将这些值放入数组中。在 BeforePackageUpload 中,您应该获取每个文件的宽度和高度值并比较它们以设置所需的转换器适合模式:
//set new arrays
var widths = [];
var heights = [];
function BeforeUpload() {
var uploader = $au.uploader('Uploader1');
count = uploader.files().count();
for (i = 0; i < count; i++) {
widths[i] = uploader.files().get(i).width();
heights[i] = uploader.files().get(i).height();
}
}
function BeforePackageUpload(index) {
var uploader = $au.uploader('Uploader1');
if (widths.shift() > heights.shift()) {
uploader.converters([{
mode: '*.*=Thumbnail',
thumbnailFitMode: 'Width',
thumbnailWidth: 500,
thumbnailHeight: 300,
thumbnailJpegQuality: 100
}]);
}
else
{
uploader.converters([{
mode: '*.*=Thumbnail',
thumbnailFitMode: 'Height',
thumbnailWidth: 300,
thumbnailHeight: 500,
thumbnailJpegQuality: 100
}]);
}
}