2016-11-14 30 views
-1

我想uplod全寬和全高圖像,這是腳本 ,但不知道哪裏的錯誤?如何圖像使用imagecreatetruecolor函數調整大小

我想要上傳全寬和高(原寬度和高度)圖片.. 檢查下面的代碼一次。此代碼返回600 400圖像,但我想要原始寬度和高度圖像。

<?php 
function create_image($file) { 
    // Content type 
    header('Content-Type: image/jpeg'); 
    header('Content-Type: text/html'); 

    // Get new sizes 
    list($width, $height) = getimagesize($file['tmp_name']); 

    // Load 
    $thumb = imagecreatetruecolor(600, 400); 

    $wmext = explode(".",$file['name']); 
    $wmext = end($wmext); 

    switch ($wmext) { 
     case 'jpg' : 
      $source = imagecreatefromjpeg($file['tmp_name']); 
      break; 
     case 'png' : 
      $source = imagecreatefrompng($file['tmp_name']); 
      break; 
     case 'gif' : 
      $source = imagecreatefromgif($file['tmp_name']); 
      break; 
     default : 
//   progress_log("Resize error for image : $file"); 
    } 

    // Resize 
    imagecopyresized($thumb, $source, 0, 0, 0, 0, 600, 400, $width, $height); 

    $final_file = "Thumb_".time()."_".$file['name']; 
    imagejpeg($thumb,"uploads/".$final_file); 

    //echo '<img src="uploads/'.$final_file.'">'; 
    imagedestroy($thumb); 
    return $final_file; 
} 
?> 
+0

我不明白,如果你想要原始的寬度和高度,你爲什麼要調整大小?你爲什麼發送矛盾的標題?或者所有頭文件? – jeroen

+0

這個腳本是從谷歌,我試圖刪除調整大小的代碼..你可以刪除調整大小代碼的工作? –

+0

你應該試試php手冊。 – jeroen

回答

1
imagecopyresized($thumb, $source, 0, 0, 0, 0, 600, 400, $width, $height); 

特殊照顧$寬度和$高度右(你想怎麼調整後的圖像是寬度和高度)應該被替換到圖像的原始寬度和高度。

雖然我不是很確定你爲什麼想調整大小圖像的原始大小。它使0有意義。