2012-10-17 93 views
0

我有一個奇怪的錯誤與這個腳本,我不知道現在去哪裏。jQuery Jcrop和PHP實際上只在IE9中裁剪圖像?

用戶上傳圖像,然後給出選項進行裁剪。一旦他們裁剪,PHP應該調整圖像大小並存儲它。

此腳本在IE8,IE7,Chrome,Safari,Firefox等中運行正常。在IE9中,它失敗了;它只是不調整圖像大小。您上傳一張500x300的圖片,將其剪裁,然後仍然以500x300圖片結束,但不會觸發任何錯誤消息。 「if(imagejpeg($ dst_r,$ src,$ jpeg_quality)){」check即使在IE9中也會返回true並重定向,但它實際上並不是編輯圖像。

所有的後期變量正在通過;如果我添加一個print_r($ _ POST);所有的維度都很好。圖像正在上傳到FTP,只是在IE9中沒有調整大小。

任何幫助將不勝感激。

<?php 

    //assign src 
    $src = $uploadStoragePath.$_SESSION['USER']['user_id'].'/'.$_SESSION['crop_me']; 

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

     //set width/height 
     $targ_w = $targ_h = 125; 

     //set jpeg quality 
     $jpeg_quality = 90; 

     //open the jpeg 
     $img_r = imagecreatefromjpeg($src); 
     $dst_r = ImageCreateTrueColor($targ_w, $targ_h); 

     //crop the jpeg 
     imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']); 

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

     //save the file 
     if(imagejpeg($dst_r,$src,$jpeg_quality)){ 
      $_SESSION['GORB']['message'] = "Profile Picture Updated!"; 
      $_SESSION['GORB']['tone'] = "happy"; 
      header('Location: '.$siteConfigMainUrl.'db/?view=edit_profile_picture'); 
     }else{ 
      echo 'Image failed'; 
     } 
    } 
?> 
<html> 
    <head> 
     <script src="<?php echo $siteConfigUrl; ?>display/js/jquery.min.js"></script> 
     <script src="<?php echo $siteConfigUrl; ?>display/js/jquery.Jcrop.min.js"></script> 
     <link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" /> 

     <script language="Javascript"> 

      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; 
      }; 

     </script> 
     <script type="text/javascript"> 

      jQuery(function($){ 

      // create variables (in this scope) to hold the API and image size 
      var jcrop_api, boundx, boundy; 

       $('#target').Jcrop({ 
        onChange: updatePreview, 
        onSelect: updatePreview, 
        aspectRatio: 1, 
        onSelect: updateCoords 
       },function(){ 
        // use the API to get the real image size 
        var bounds = this.getBounds(); 
        boundx = bounds[0]; 
        boundy = bounds[1]; 
        // store the API in the jcrop_api variable 
        jcrop_api = this; 
       }); 

       function updatePreview(c){ 

        if (parseInt(c.w) > 0){ 
         var rx = 125/c.w; 
         var ry = 125/c.h; 

         $('#preview').css({ 
          width: Math.round(rx * boundx) + 'px', 
          height: Math.round(ry * boundy) + 'px', 
          marginLeft: '-' + Math.round(rx * c.x) + 'px', 
          marginTop: '-' + Math.round(ry * c.y) + 'px' 
         }); 
        } 
       }; 
      }); 
     </script> 
    </head> 
    <body> 
     <div class="article"> 
      <img src="<?php echo $uploadStoragePath.$_SESSION['USER']['user_id'].'/'.$_SESSION['crop_me'];?>" id="target" /> 
      <br/> 
      <h1>Preview:</h1> 
      <div style="width:125px;height:125px;overflow:hidden;"> 
       <img src="<?php echo $uploadStoragePath.$_SESSION['USER']['user_id'].'/'.$_SESSION['crop_me'];?>" id="preview" alt="Preview" /> 
      </div> 

      <form action="<?php echo $siteConfigUrl.'?view=crop_profile_picture'; ?>" method="POST" onsubmit="return checkCoords();"> 
       <input type="hidden" id="x" name="x" /> 
       <input type="hidden" id="y" name="y" /> 
       <input type="hidden" id="w" name="w" /> 
       <input type="hidden" id="h" name="h" /> 
       <input type="submit" value="Crop Image" /> 
      </form> 
     </div> 
    </body> 
</html> 
+0

什麼也沒有被輸出到error_log。如果我打開\t'ini_set('display_errors',1);''和'error_reporting(E_ALL);'也不輸出錯誤。它仍然會顯示「個人資料圖片已更新!」在IE9中,但它並沒有裁剪它。 – ihateartists

回答

0

最後幾天我有同樣的問題。我用這個來解決。我希望這適用於你:

if ($_SERVER['REQUEST_METHOD'] == 'POST') 
    { 
$targ_w = $_POST['w'];$targ_h = $_POST['h']; 
$jpeg_quality = 100; 
$image = $_POST['image']; 
$dir = $_POST['rel']; 
$imagen = $dir."/".$image; 
$src = $imagen; 
$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, $dir.'/crop_'.$image.'', $jpeg_quality); 

exit; 
    }