2017-07-17 115 views
1

我想创建一个从固定大小(400 * 320) 保存在缩略图文件夹和原始图像的副本用户上传图像的缩略图发送到上传文件夹时,用户点击缩略图。原始图像出现,但原始图像上传的代码问题是缩略图的任何解决方案,请相同大小?调整图像大小固定的规模和保持原始图像大小

下面是代码:

function ak_img_resize($target, $newcopy, $w, $h, $ext) { 
    list($w_orig, $h_orig) = getimagesize($target); 

    $img = ""; 
    $ext = strtolower($ext); 
    if ($ext == "gif"){ 
     $img = imagecreatefromgif($target); 
    } else if($ext =="png"){ 
     $img = imagecreatefrompng($target); 
    } else { 
     $img = imagecreatefromjpeg($target); 
    } 
    $w = 400; 
    $h = 320; 
    $tci = imagecreatetruecolor($w, $h); 
    // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h) 
    imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig); 
    imagejpeg($tci, $newcopy, 90); 
+0

我发送上传图片的代码并使用resize_img.php文件。请为我做的IAM没有开发者,我需要从你把代码并将其粘贴 –

+0

非常感谢.CODE工作 –

回答

0

想必你是把原来通过此功能,这也许就是因为你试图进行压缩或什么的,但如果你想原来住原来的大小,只需将上传文件到它去,然后再在该文件上的成功被移动,使缩略图副本从移动文件。

如果你想要把原始图像文件通过你的功能,按比例回的质量也好,都试图进行这些调整:

# Notice the re-organizing of the params--------vv----------vv 
function ak_img_resize($target, $newcopy, $ext, $w = false, $h = false) 
    { 
     list($w_orig, $h_orig) = getimagesize($target); 
     # If you keep the width empty, take original size 
     if(empty($w)) 
      $w = $w_orig; 
     # If you keep the height empty, take original size 
     if(empty($h)) 
      $h = $h_orig; 

     $img = ""; 
     $ext = strtolower($ext); 
     if ($ext == "gif"){ 
      $img = imagecreatefromgif($target); 
     } else if($ext =="png"){ 
      $img = imagecreatefrompng($target); 
     } else { 
      $img = imagecreatefromjpeg($target); 
     } 
     $tci = imagecreatetruecolor($w, $h); 
     // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h) 
     imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig); 
     imagejpeg($tci, $newcopy, 90); 
    } 

使用方法:

#Sized down: 
ak_img_resize($target,$newcopy,$ext,400,320); 

#Original: 
ak_img_resize($target,$newcopy,$ext);