设为首页 收藏本站
查看: 490|回复: 0

[经验分享] php 截图(可预览) crop images thumb jcrop/asido

[复制链接]

尚未签到

发表于 2017-4-9 12:57:03 | 显示全部楼层 |阅读模式
  jcrop + asido 
  index.php

<?php
$targ_w = 90; // thumb width size
$targ_h = 89; // thumb height size
$filename = $_GET['file'];
if($filename)
{
$abs = '/home/www';
$fullsrc = '/public/images/'.$filename; // absolute path of original image uploaded
$thumbsrc = '/public/images/thumb-'.$filename; // absolute path of thumb image you want
$fullroot = $abs.$fullsrc;
$thumbroot = $abs.$thumbsrc;
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
include('asido/class.asido.php');
asido::driver('gd');
$i1 = asido::image($fullroot, $thumbroot);
Asido::Crop($i1, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
$i1->save(ASIDO_OVERWRITE_ENABLED);
// if you want to make resize via scale automatically, or you can remove it
$i1 = asido::image($thumbroot, $thumbroot);
Asido::resize($i1, $targ_w, $targ_h, ASIDO_RESIZE_STRETCH);
$i1->save(ASIDO_OVERWRITE_ENABLED);
exit('<img src="'.$thumbsrc.'" /><br><a href="?file='.$filename.'&sv='.time().'">Create Thumbnail Again</a>');
}
?>
<!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>Add a New WithStars</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="GLS PHP Framework">
<meta name="author" content="GLS">
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:01 GMT" />
<meta http-equiv="expires" content="0" />
<script type="text/javascript" src="js/jquery.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jcrop.js"></script>
<script>
jQuery(function($){
// Create variables (in this scope) to hold the API and image size
var jcrop_api, boundx, boundy;
$('#cropbox').Jcrop({
onChange: updatePreview,
onSelect: updatePreview,
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 updatePreview(c)
{
if (parseInt(c.w) > 0)
{
$('#x').val(c.x);
$('#y').val(c.y);
var rx = <?=$targ_w?> / c.w;
var ry = <?=$targ_h?> / c.h;
$('#w').val(c.w);
$('#h').val(c.h);
// if you don't want to preview, you can remove it
$('#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'
});
}
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
});
</script>
<link href="css/jcrop.css" rel="stylesheet" type="text/css" />
<body>
<form method="post" >
<table>
<tr>
<td><img src="<?=$fullsrc?>" id="cropbox" /></td>
<td>
<h4>Preview pane:</h4>
<div style="overflow: hidden; width: <?=$targ_w?>px; height: <?=$targ_h?>px;border:#ccc 1px solid;padding:3px;"><img id="preview" src="<?=$fullsrc?>"/></div>
<div style="margin:5px;"><input type="submit" name="crop" value="Crop Image" /></div>
</td>
</tr>
</table>
<div style="margin:5px;">
<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" />
</div>
</form>
</body>
</html>
<?php }?>
   jcrop.css

.jcrop-holder { text-align: left; }
.jcrop-vline, .jcrop-hline
{
font-size: 0;
position: absolute;
background: white url('jcrop.gif') top left repeat;
}
.jcrop-vline { height: 100%; width: 1px !important; }
.jcrop-hline { width: 100%; height: 1px !important; }
.jcrop-handle {
font-size: 1px;
width: 7px !important;
height: 7px !important;
border: 1px #eee solid;
background-color: #333;
*width: 9px;
*height: 9px;
}
.jcrop-tracker { width: 100%; height: 100%; }
.custom .jcrop-vline,
.custom .jcrop-hline
{
background: yellow;
}
.custom .jcrop-handle
{
border-color: black;
background-color: #C7BB00;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}

   参考来源:
  http://asido.info/
  http://asido.info/about/features/

  http://sourceforge.net/projects/asido/
  http://deepliquid.com/content/Jcrop.html

  http://code.google.com/p/jcrop/

  转帖注明:justcoding
 
http://justcoding.iteye.com/blog/1430913

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-362436-1-1.html 上篇帖子: 10个最好的PHP网站后台管理系统 下篇帖子: php 实现图片等比例缩放 原理(初级)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表