2012-04-24 66 views
2

餵我使用一個名爲aurigma一個基於java的圖片上傳,並使用PHP代碼設置它。aurigma條件調整大小

我有,可以在寬度或高度被設置一些大小調整選項。

我希望做一個檢查,我說:

If ((image I am uploading width) > (image I am uploading height)){ 
    $converter->setThumbnailFitMode("Width"); 
}else{ 
    $converter->setThumbnailFitMode("Height"); 
} 

我如何檢查,我上傳到aurigma文件的大小,並設置基於這一條件。即

+0

大 - 你有什麼問題嗎? – madflow 2012-04-24 14:27:26

+0

編輯我的問題。希望這現在更有意義? – jaget 2012-04-24 14:38:18

回答

1

如果您需要設置在運行時轉換器,你將需要設置aurigma上傳的兩個額外的事件:1.BeforeUpload和2 BeforePackageUpload:

uploader = new Uploader('Uploader1'); 
    ... 
    $uploader->getClientEvents()->setBeforeUpload("BeforeUpload"); 
    $uploader->getClientEvents()->setBeforePackageUpload("BeforePackageUpload"); 
    ... 

然後實現在Javascript塊事件的代碼(腳本type =「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 
    }]); 
    } 
}