很多站长朋友们都不太清楚Jcrop配合php,今天小编就来给大家整理Jcrop配合php,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php求助图片缩放裁切问题 2、 怎么实现php上传图片并可以裁剪的功能,类似一些网站的头像截取,裁剪可以用jcrop插件。高分悬赏 3、 php中的jcrop可以将选框移动到图片区域外面吗 php求助图片缩放裁切问题这段代码可以通过自已选择来决定图片的大小!
效果图如下所示:希望对你有帮助!
其中
minSize: [48,48],
setSelect: [0,0,190,190],
是调整选取范围的大小,若你 调整为120和160就改为了
setSelect: [0,0,120,160],
就可以了!
<?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 = "/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg";
$res = $images->thumb($image,false,1);
if($res == false){
echo "裁剪失败";
}elseif(is_array($res)){
echo '<img src="'.$res['big'].'" style="margin:10px;">';
echo '<img src="'.$res['small'].'" style="margin:10px;">';
}elseif(is_string($res)){
echo '<img src="'.$res.'">';
}
}elseif(isset($_GET['act']) $_GET['act'] == "upload"){
$path = $images->move_uploaded();
$images->thumb($path,false,0); //文件比规定的尺寸大则生成缩略图,小则保持原样
if($path == false){
$images->get_errMsg();
}else{
echo "上传成功!<a href='".$path."' target='_blank'>查看</a>";
}
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ";quot;;>
<html>
<head>
<meta name="Author" content="SeekEver">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<script src="./js/jquery.min.js" type="text/javascript"></script>
<script src="./js/jquery.Jcrop.js" type="text/javascript"></script>
<link rel="stylesheet" href="./css/jquery.Jcrop.css" type="text/css" />
<script type="text/javascript">
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'
});
}
};
});
</script>
</head>
<body>
<form method="post" action="?act=upload" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="上传">
</form>
<div style="float:left;"><img id="target" src="/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<div style="width:48px;height:48px;margin:10px;overflow:hidden; float:left;"><img style="float:left;" id="preview" src="/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<div style="width:190px;height:195px;margin:10px;overflow:hidden; float:left;"><img style="float:left;" id="preview2" src="/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<form action="index.php?act=cut" method="post" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="submit" value="裁剪" />
</form>
</body>
</html>
<?php
}
?>
怎么实现php上传图片并可以裁剪的功能,类似一些网站的头像截取,裁剪可以用jcrop插件。高分悬赏php本身有裁剪图片的函数,js的截取一般是获得几个坐标,供这个函数作为参数,php在图片上传到服务器临时空间的时候,对图片进行裁剪,再按编程人的需求保存到指定目录。
百度下现成的,或者翻翻手册。
php中的jcrop可以将选框移动到图片区域外面吗搞清楚这个插件的原理之后,这个问题就迎刃而解了。
jcrop是在图片上选点也就是图片的坐标,然后把坐标传到后台php进行图片的剪切操作。
只要你设置了外层是可以获取到坐标的,但是传到后台处理比较麻烦。
关于Jcrop配合php的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于Jcrop配合php php调用javascript的详细内容...