2012-05-23 36 views
-2

我用這webcam plugin的圖像,拍攝後的圖像(默認爲320x240),我想將圖像尺寸重新爲100x100(對於資料圖片拍攝)。
我試過使用縮放,但它裁剪圖像不調整圖像。重新調整使用Javascript

+0

320x240的不是很大。將其上傳到您的服務器並在此處調整大小。 – Endophage

+0

由於240x320和100x100是不同的形狀,因此無法按比例將240x320縮放到100x100。你可以強制它達到100x100,但它會在一個方向上被壓扁,而正方形或圓形的東西將不再具有它們的原始形狀。或者,您可以剪切長邊並將其縮小到100x100,以僅顯示圖像的正方形部分。你想要做什麼? – jfriend00

+0

我在客戶端顯示空間限制,如果我再次在服務器端調整大小,必須從那裏加載。即使圖像質量沒有問題,也可以使用 – jayanth

回答

0

您可以使用img標籤本身重新大小的圖像

<img src='./imagename.jpg' style="display: inline; width: 100px; height: 100px"> 

難道ü想什麼?你可以這樣做Java腳本也

0

這裏是調整圖像的編碼。

這裏, '這個' 代表形象。 var maxWidth = 320; //圖片的最大寬度 var maxHeight = 240; //圖像的最大高度 var ratio = 0; //用於縱橫比 var width = $(this).width(); //當前圖像寬度 var height = $(this).height(); //當前圖像高度

// Check if the current width is larger than the max 
    if(width > maxWidth){ 
     ratio = maxWidth/width; // get ratio for scaling image 
     $(this).css("width", maxWidth); // Set new width 
     $(this).css("height", height * ratio); // Scale height based on ratio 
     height = height * ratio; // Reset height to match scaled image 
     width = width * ratio; // Reset width to match scaled image 
    } 

    // Check if current height is larger than max 
    if(height > maxHeight){ 
     ratio = maxHeight/height; // get ratio for scaling image 
     $(this).css("height", maxHeight); // Set new height 
     $(this).css("width", width * ratio); // Scale width based on ratio 
     width = width * ratio; // Reset width to match scaled image 
    }