Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Obcinanie obrazka przy uploadzie
deha21
post 17.08.2010, 11:13:35
Post #1





Grupa: Zarejestrowani
Postów: 544
Pomógł: 5
Dołączył: 18.08.2009

Ostrzeżenie: (0%)
-----


Mam kod który pomniejsza obrazek i wycina go jako kwadrat 150x150px:
  1. function resize2($filef, $new_width, $new_height, $thumb, $quality) {
  2. $info = getimagesize($filef);
  3. if ($info === false)
  4. return false;
  5. $img = null;
  6. switch($info[2]){
  7. case IMAGETYPE_JPEG:
  8. $img = imagecreatefromjpeg($filef);
  9. break;
  10. case IMAGETYPE_GIF:
  11. $img = imagecreatefromgif($filef);
  12. break;
  13. case IMAGETYPE_PNG:
  14. $img = imagecreatefrompng($filef);
  15. break;
  16. default:
  17. return false;
  18. }
  19. $th = imagecreatetruecolor(150, 150);
  20.  
  21. switch($info[2]){
  22. case IMAGETYPE_JPEG:
  23. imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]);
  24. imagejpeg($th, $filef, $quality);
  25. break;
  26. case IMAGETYPE_GIF:
  27. imagealphablending($th, true);
  28. imagetruecolortopalette($img, true, 256);
  29. imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]);
  30. imagegif($th, $filef);
  31. break;
  32. case IMAGETYPE_PNG:
  33. imagealphablending($th, false);
  34. imagesavealpha($th, true);
  35. imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]);
  36. imagepng($th, $filef);
  37. break;
  38. }
  39. imagedestroy($th);
  40. imagedestroy($img);
  41. return true;
  42.  
  43. }
  44.  
  45. if ($infoo[0]<=$infoo[1]) {
  46. copy("../files/gallery/".$id."/".$file,"../files/gallery/".$id."/thumb_".$file);
  47. $thumb_height = (150/$infoo[0])*$infoo[1];
  48. resize2("../files/gallery/".$id."/thumb_".$file, 150, $thumb_height, "../files/gallery/".$id."/thumb_".$file, 95);
  49. } elseif ($infoo[0]>$infoo[1]) {
  50. copy("../files/gallery/".$id."/".$file,"../files/gallery/".$id."/thumb_".$file);
  51. $thumb_width=(150*$infoo[0])/$infoo[1];
  52. resize2("../files/gallery/".$id."/thumb_".$file, $thumb_width, 150, "../files/gallery/".$id."/thumb_".$file, 95);
  53. }
  54.  


Teraz chcę zrobić żeby robił to na tej samej zasadzie ale miniaturki 300x150px z tym że oczywiście powinien je obcinać proporcjonalnie. Gdy wrzucę imagecreatetruecolor(300, 150); To robi miniaturki o tej wysokości ale po prawej jest czarne tło - logiczne bo tam się kończy obrazek.

Jak to rozwiązać?


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 20.07.2025 - 02:58