2011-09-22 57 views
1

我想爲我的用戶提供通過jCrop裁剪上傳圖像的能力。結果應該是方形格式。選擇應該在圖像中居中顯示,沿最短維度的任何一邊都有大約10%的間隙。當前代碼:jCrop:設置任何尺寸的上傳圖像的方形選擇(居中)

 jcrop_api = $.Jcrop('#imgCrop', { 
      onSelect: storeCoords, 
      onChange: storeCoords, 
      aspectRatio: 1 
      setSelect: [20, 20, 280, 280] 
     }); 

因此而不是硬編碼值,我需要一種方法來X1,Y1,X2,Y2值設置爲正確的位置。

回答

0

使用從preview method的座標參數數組:

jcrop_api = $.Jcrop('#imgCrop', { 
     onSelect: storeCoords, 
     onChange: storeCoords, 
     aspectRatio: 1 
     setSelect: [ ($('#imgCrop').attr('width')/2) - 10, 
         ($('#imgCrop').attr('height')/2) - 10, 
         ($('#imgCrop').attr('width')/2) + 10, 
         ($('#imgCrop').attr('height')/2) + 10 
        ] 
     }); 

這將需要一些試驗和錯誤,找到模式,並得到它的工作始終。