我正在使用Jcrop裁剪来自用户的图像。我按照教程:http://deepliquid.com/content/Jcrop_Implementation_Theory.html。这是我的代码
<script type="text/javascript">
$(document).ready(function() {
$("#sidebar li").click(function(){
$("#sidebar li").removeClass('active');
$(this).addClass('active') ;
});
});
</script>
我已检查目录和文件是否可写(0777权限)。我正在使用的所有变量都是明确定义的,没有任何错误。但是,最终图像仍然是原始形式,没有裁剪。
有谁知道它为什么不起作用?任何帮助表示赞赏。
答案 0 :(得分:1)
您正在使用list()
获取源图片的宽度和高度,但您未在imagecopyresampled()
调用中使用它。就我所见,其他一切看起来都很好,如果不能解决问题,问题可能就是班上的其他地方。
这是我的裁剪方法供参考,如果有帮助的话。
/**
* Crops the image to the given dimensions, at the given starting point
* defaults to the top left
* @param type $width
* @param type $height
* @param type $x
* @param type $y
*/
public function crop($new_width, $new_height, $x = 0, $y = 0){
$img = imagecrop($this->image, array(
"x" => $x,
"y" => $y,
"width" => $new_width,
"height" => $new_height
));
$this->height = $new_height;
$this->width = $new_width;
if(false !== $img) $this->image = $img;
else self::Error("Could not crop image.");
return $this;
}
<小时/>
调整大小的方法,供参考..
/**
* resizes the image to the dimensions provided
* @param type $width (of canvas)
* @param type $height (of canvas)
*/
public function resize($width, $height){
// Resize the image
$thumb = imagecreatetruecolor($width, $height);
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
imagecopyresampled($thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
$this->image = $thumb;
$this->width = $width;
$this->height = $height;
return $this;
}