2013-02-23 46 views
1

我正在使用jcrop来制作图像作物。
但由此产生的croped图像不能保存,我的意思是当我点击右键并保存图像时,它会保存.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

,什么是PHP文件里? – zerkms 2013-02-23 21:34:49

+0

上面提到的顶级php代码,下面是发送数据到这个部分创建作物的html/jquery表单。 – 2013-02-23 21:35:58

+0

不,我的意思是 - 你有没有试图打开保存的PHP文件? – zerkms 2013-02-23 21:39:11

回答

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_ziseheader("Content-length:" . $f_size);您可以使用此功能getSizeFilephp.net

请测试...

+0

Stil问题依然存在。试试你的自我。这里:http://www.imageopti.com/index_crop.php?name=1361661584.jpg – 2013-02-23 23:20:09

+0

当你得到输出croped图像。点击右键并点击保存 – 2013-02-23 23:21:00

+0

我编辑,请尝试它,并告诉我,如果一切正常! – 2013-02-24 01:54:37