上传裁图的插件php,jcrop插件+php实现的图片上传与裁剪

error_reporting(7);

date_default_timezone_set("Asia/Shanghai");

header("Content-type:text/html; Charset=utf-8");

require_once("./image.class.php");

$images = new Images("file");

if ($_GET['act'] == 'cut'){

$image = "0000.jpg";

$res = $images->thumb($image,false,1);

if($res == false){

echo "裁剪失败";

}elseif(is_array($res)){

echo ''.%24res%5B'big'%5D.'';

echo ''.%24res%5B'small'%5D.'';

}elseif(is_string($res)){

echo ''.%24res.'';

}

}elseif(isset($_GET['act']) && $_GET['act'] == "upload"){

$path = $images->move_uploaded();

$images->thumb($path,false,0); //文件比规定的尺寸大则生成缩略图,小则保持原样

if($path == false){

$images->get_errMsg();

}else{

echo "上传成功!查看";

}

}else{

?>

ttp://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd">

jQuery(function($){

// Create variables (in this scope) to hold the API and image size

var jcrop_api, boundx, boundy;

$('#target').Jcrop({

minSize: [48,48],

setSelect: [0,0,190,190],

onChange: updatePreview,

onSelect: updatePreview,

onSelect: updateCoords,

aspectRatio: 1

},

function(){

// Use the API to get the real image size

var bounds = this.getBounds();

boundx = bounds[0];

boundy = bounds[1];

// Store the API in the jcrop_api variable

jcrop_api = this;

});

function updateCoords(c)

{

$('#x').val(c.x);

$('#y').val(c.y);

$('#w').val(c.w);

$('#h').val(c.h);

};

function checkCoords()

{

if (parseInt($('#w').val())) return true;

alert('Please select a crop region then press submit.');

return false;

};

function updatePreview(c){

if (parseInt(c.w) > 0)

{

var rx = 48 / c.w; //小头像预览Div的大小

var ry = 48 / c.h;

$('#preview').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'

});

}

{

var rx = 199 / c.w; //大头像预览Div的大小

var ry = 199 / c.h;

$('#preview2').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'

});

}

};

});

0000.jpg
0000.jpg
0000.jpg

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值