色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP結合JQueryJcrop實現圖片裁切實例詳解

我們經常可以看到一些網站上有圖片剪切的功能,或許你會覺得這一功能炫目華麗,神秘莫測!但是今天介紹的一款專用于圖片裁切的插件jquery.Jcrop.min.js就將揭開圖片剪切的神秘面紗。使用這個插件可以很方便的實現這一功能,使用時僅需鼠標在圖片上圈選出選區,即可把圖片裁切成所選部分,非常適合用于頭像的裁切編輯功能。

本實例演示分為HTML和php兩部分:

第一部分,HTML代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Jcrop實現圖片裁剪</title><script src="./jquery-1.6.2.min.js"></script><script src="./jquery.Jcrop.min.js"></script><link rel="stylesheet" href="./jquery.Jcrop.min.css" rel="external nofollow" type="text/css" /><style type="text/css">#preview{width:100px;height:100px;border:1px solid #000;overflow:hidden;}#imghead{filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}</style><script language="Javascript">jQuery(function(){ jQuery('#imghead').Jcrop({ ASPectRatio: 1, onSelect: updateCoords, //選中區域時執行對應的回調函數 onChange: updateCoords, //選擇區域變化時執行對應的回調函數 });});function updateCoords(c){ jQuery('#x').val(c.x); //選中區域左上角橫 jQuery('#y').val(c.y); //選中區域左上角縱坐標 //jQuery("#x2").val(c.x2); //選中區域右下角橫坐標 //jQuery("#y2").val(c.y2); //選中區域右下角縱坐標 jQuery('#w').val(c.w); //選中區域的寬度 jQuery('#h').val(c.h); //選中區域的高度};function checkCoords(){ if (parseInt(jQuery('#w').val())>0) return true; alert('請選擇需要裁切的圖片區域.'); return false;};</script></head><body><img id="imghead" border=0 src='./image/b4.jpg' /><form action="crop.php" method="post" onsubmit="return checkCoords();"> <input type="text" id="x" name="x" /> <input type="text" id="y" name="y" /> <input type="text" id="w" name="w" /> <input type="text" id="h" name="h" /> <input type="submit" value="提交"></form></body></html>

第二部分:php處理部分crop.php

<?phpif ($_SERVER['REQUEST_METHOD'] == 'POST'){ $targ_w = $targ_h = 150; $jpeg_quality = 90; $src = './image/b4.jpg'; $img_r = imagecreatefromjpeg($src); $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']); header('Content-type: image/jpeg'); imagejpeg($dst_r,null,$jpeg_quality); exit;}?>

補充:jquery.Jcrop.min.js本站下載地址:http://www.jb51.NET/jiaoben/24768.html

php技術PHP結合JQueryJcrop實現圖片裁切實例詳解,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 徐州市| 东莞市| 吉隆县| 东乡族自治县| 迁西县| 宁武县| 辽宁省| 钟祥市| 博爱县| 榆树市| 丰镇市| 吴桥县| 故城县| 集贤县| 蒲江县| 朔州市| 绿春县| 西平县| 平江县| 阿巴嘎旗| 宜阳县| 桃园市| 玛纳斯县| 镇雄县| 康定县| 温州市| 张家川| 闽清县| 锡林浩特市| 宁南县| 荆门市| 敦化市| 罗江县| 北流市| 错那县| 岱山县| 县级市| 泽州县| 蓬莱市| 庄浪县| 明星|