jQuery 圖片剪裁外掛程式初探之 Jcrop

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   使用   java   sp   

首頁:http://deepliquid.com/content/Jcrop.html

官方:http://deepliquid.com/content/Jcrop_Download.html

下載包中除了 CSS 檔案夾和 js 檔案夾外還提供了幾款 demo:

1. non-image.html 不包含映像的任意 div 的剪裁方式:

2.styling.html

提供了 3 種可以選擇的遮罩色、透明度和選區邊框樣式 jcrop-light ( bgcolor:#fff opacity:0.5 ) , jcrop-dark ( bgcolor:#000 opacity:0.4 ) , normal ( bgcolor:#000 opacity:0.6 )

3.tutorial1.html

Jcrop 的預設設定:

原圖的 html 部分為:

<img src="demo_files/sago.jpg" id="target" alt="[Jcrop Example]" />

此時在 js 中使用:

<script type="text/javascript">  jQuery(function($){    // How easy is this??    $(‘#target‘).Jcrop();  });</script>

就可以顯示預設的最簡單的 demo 的效果。

 

4. tutorial2.html

顯示左上、右下座標值和選區寬高值

5.tutorial3.html

固定選區長寬比並顯示預覽圖

預覽圖的顯示機制和 imgAreaSelect 類似,見 line:42

 function updatePreview(c)    {      if (parseInt(c.w) > 0)      {        var rx = xsize / c.w;        var ry = ysize / c.h;        $pimg.css({          width: Math.round(rx * boundx) + ‘px‘,          height: Math.round(ry * boundy) + ‘px‘,          marginLeft: ‘-‘ + Math.round(rx * c.x) + ‘px‘,          marginTop: ‘-‘ + Math.round(ry * c.y) + ‘px‘        });      }  };

參數 c 是選區,c.w 代表選區的寬,c.h 代表選區的高;xsize 和 ysize 分別是預覽視窗的寬和高;縮放比為 rx 與 ry 分別等於預覽視窗的寬和高除以選區的寬和高;boundx 是原圖的寬,boundy 是原圖的高,見 jquery_Jcrop.js line:328:

  var boundx = $img.width(),      boundy = $img.height(),

最後呈現在預覽視窗中預覽圖的寬度等於縮放比乘以原圖的寬高,這個處理和  imgAreaSelect 外掛程式時一致的。

 

如果要改變選區的寬高比,只需在 demo html 中改變 line:91 #preview-pane .preview-container 的寬度和高度即改變預覽視窗的寬度和高度,同時選區的寬高比也隨著預覽視窗的改變發生改變並和預覽視窗寬高比一致。

圖示預覽圖的寬度和高度為:

#preview-pane .preview-container {  width: 250px;  height: 170px;  overflow: hidden;}

修改為:

#preview-pane .preview-container {  width: 220px;  height: 220px;  overflow: hidden;}

 

6.tutorial4.html

帶有各種動畫和過渡的選區變換、背景透明度和背景顏色的過渡轉變,很炫

7.tutorial5.html API Demo

demo 檔案夾中還提供了 crop.php,把選取的圖片真正剪裁出來。

 

更多內容:官方文檔

中文文檔

jQuery 圖片剪裁外掛程式初探之 Jcrop

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.