---
title: "web头像上传 裁剪 剪切功能"
author: "fackyou200"
date: "2011-11-11T16:33:23Z"
tags: []
categories: ["Web前端"]
slug: "web"
draft: false
lastmod: "2011-11-14T11:45:40Z"
id: 1254463
url: "https://fackyou200.iteye.com/blog/1254463"
---

![](http://dl.iteye.com/upload/attachment/587868/85550548-7906-35a8-a84f-3b31fcf4e692.jpg)

 

 

![](http://dl.iteye.com/upload/attachment/587870/1829cfda-3d6b-33e5-8357-067d5b6f5038.jpg)

 

 

 

1、首先安装ImageMagick-6.3.7-Q16

2、上传路径修改：1、avtar.js         65行   upload   
                          2、crop.jsp        26行  
                          3、crop.jsp        78行  
                          4、savefile.jsp   55行

3、服务器端图片处理：crop.jsp  36行 String cmd = "C:\\\\Tools\\\\ImageMagick-6.3.7-Q16\\\\convert ";

4、图片裁剪大小修改：crop.jsp  43行  cmd += " -quality 100 -crop 120x120!";

5、改变预览头像大小：my.css    35行  #preDiv

6、改变中间方块大小：my.css    26行  #wrap #shadow  width:120px;  height:120px;

 

 

7、修改cropPic()方法使用iframe提交

 

```
function cropPic() {
	var frm = $('uploadFrm');
	frm.action = './crop.jsp';
	//frm.target = '_blank';
	frm.target = 'upload_iframe';




	frm.encoding = 'application/x-www-form-urlencoded';
	$('top').value = parseInt(top) - (PICHEIGHT / 2);
	$('left').value = parseInt(left) - (PICWIDTH / 2);
	$('rate').value = latestRate;
	//alert('');
	frm.submit();
}
```

 

8、修改crop.jsp页面，调用父窗体方法aa传回裁剪完图片名称

 

```
<script>
 window.parent.aa('"/upload/"+resultPicName%>');
</script>
```