php 图片裁剪后保存,php – 如何保存裁剪的图像

从以下链接下载用于裁剪图像的代码:

这是crop.php页面中的代码:

/**

* Jcrop image cropping plugin for jQuery

* Example cropping script

* @copyright 2008-2009 Kelly Hallman

* More info: http://deepliquid.com/content/Jcrop_Implementation_Theory.html

*/

if ($_SERVER['REQUEST_METHOD'] == 'POST')

{

$targ_w = $targ_h = 150;

$jpeg_quality = 90;

$src = 'demo_files/pool.jpg';

$img_r = imagecreatefromjpeg($src);

$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],

$targ_w,$targ_h,$_POST['w'],$_POST['h']);

header('Content-type: image/jpeg');

imagejpeg($dst_r,null,$jpeg_quality);

exit;

}

// If not a POST request, display page below:

?>

Untitled Document

$(function(){

$('#cropbox').Jcrop({

aspectRatio: 1,

onSelect: updateCoords

});

});

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;

};

pool.jpg

完美裁剪并成功显示裁剪后的图像.

但我想将裁剪后的图像保存到目录中.

我怎样才能做到这一点?

解决方法:

试试这个:

imagejpeg($dst_r, 'yourfilename.jpg', $jpeg_quality);

// Remove from memory - don't forget this part

imagedestroy($dst_r);

标签:jquery,php,javascript,jcrop

来源: https://codeday.me/bug/20190630/1332915.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值