我正在使用jcrop制作图像
但是由此产生的图像不能保存,我的意思是当我右键单击并保存图像时,它会保存.php文件。
以下是使用的代码:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targ_iw = $_REQUEST['iwidth'];
$targ_ih = $_REQUEST['iheight'];
$source = $_REQUEST['tname'];
if(empty($targ_iw)){
$targ_iw = $_POST['w'];
$targ_ih = $_POST['h'];
}
$jpeg_quality = 90;
$src = 'http://www.imageopti.com/crop/files/'.$source;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_iw, $targ_ih );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_iw,$targ_ih,$_POST['w'],$_POST['h']);
header('Content-type: image/jpeg');
imagejpeg($dst_r, null, $jpeg_quality);
exit;
}
答案 0 :(得分:1)
在您的HTML代码中,添加
<input type="hidden" name="create" value="true" />
添加我的功能
function new_my_resampled($source, $iwidth, $iheight, $w, $h, $x, $y)
{
$filename = "http://www.imageopti.com/crop/files/" . $source;
$targ_iw = $iwidth;
$targ_ih = $iheight;
if(empty($targ_iw))
{
$targ_iw = $w;
$targ_ih = $h;
}
$image = imagecreatetruecolor($targ_iw,$targ_ih);
$o_img = imagecreatefromjpeg($filename);
imagecopyresampled($image,$o_img,0,0,$x,$y,$targ_iw,$targ_ih,$w,$h);
imagejpeg($image, null, 100);
}
在你的php文件中添加
if($_POST['create'] == 'true')
{
/*
* Write here your conditions
*/
$filename = "http://www.imageopti.com/crop/files/" . $_POST['tname'];
$f_name = trim(basename($filename));
//$f_size = getSizeFile($filename);
header("(anti-spam-content-type:) image/jpeg");
header('Cache-control: max-age=31536000');
header('Expires: ' . gmdate('D, d M Y H:i:s', (time() + 31536000)) . ' GMT');
header('Content-transfer-encoding: binary');
header('ETag: "' . time() . '"');
header("Content-Disposition: attachment; filename=" . $f_name);
header("Content-type: image/jpeg");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
//header("Content-length:" . $f_size);
header("Cache-control: private");
new_my_resampled($_POST['tname'], $_POST['iwidth'], $_POST['iheight'], $_POST['w'], $_POST['h'],$_POST['x'],$_POST['y']);
}
$f_zise
和header("Content-length:" . $f_size);
,可以使用php.net getSizeFile
请测试一下......