Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Postrzępione miniatury
Forum PHP.pl > Forum > PHP
patrykt
mam prosty skrypt do robienia trzech różnej wielkości miniatur z jednego, uploadowanego przez nas. jednakże wynikowe obrazki mają ostre, postrzępione brzegi (http://lema.dtl.pl/foto/s_AC_25.jpg). jakieś pomysły?

  1. <? 
  2. if(isset($_FILES['plik']) && $_FILES['plik']['tmp_name']!="") 
  3. { 
  4. list($www, $hh, $type, $attr) = getimagesize($_FILES['plik']['tmp_name']); 
  5. if($type!=2) 
  6. { 
  7. echo"proszę uploadować tylko pliki JPG!"; 
  8. exit; 
  9. } 
  10.  
  11. $_POST['towkod']=str_replace(" ", "_", $_POST['towkod']); 
  12. $filename = 'foto/'.$_POST['towkod'].'.jpg'; 
  13.  
  14. if(move_uploaded_file($_FILES['plik']['tmp_name'], $filename)) 
  15. { 
  16.  
  17. list($width_orig, $height_orig) = getimagesize($filename); 
  18.  
  19. ////////////////// 1 //////////////////////////// 
  20. $width = 40; 
  21. $height = 40; 
  22. if ($width && ($width_orig < $height_orig)) 
  23. $width = ($height / $height_orig) * $width_orig; 
  24. else 
  25. $height = ($width / $width_orig) * $height_orig; 
  26. $thumb = imagecreatetruecolor($width, $height); 
  27. $source = imagecreatefromjpeg($filename); 
  28. imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); 
  29. imagejpeg($thumb, "foto/m_".$_POST['towkod'].".jpg", 100); 
  30. ////////////////// 2 //////////////////////////// 
  31. $width = 195; 
  32. $height = 195; 
  33. if ($width && ($width_orig < $height_orig)) 
  34. $width = ($height / $height_orig) * $width_orig; 
  35. else 
  36. $height = ($width / $width_orig) * $height_orig; 
  37. $thumb = imagecreatetruecolor($width, $height); 
  38. $source = imagecreatefromjpeg($filename); 
  39. imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); 
  40. imagejpeg($thumb, "foto/s_".$_POST['towkod'].".jpg", 100); 
  41. ////////////////// 3 //////////////////////////// 
  42. $width = 600; 
  43. $height = 600; 
  44. if ($width && ($width_orig < $height_orig)) 
  45. $width = ($height / $height_orig) * $width_orig; 
  46. else 
  47. $height = ($width / $width_orig) * $height_orig; 
  48. $thumb = imagecreatetruecolor($width, $height); 
  49. $source = imagecreatefromjpeg($filename); 
  50. imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); 
  51. imagejpeg($thumb, $filename, 100); 
  52. ///////////////////////////////////////////////// 
  53. } 
  54. } 
  55. ?>
patrykt
<ukłony>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.