Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [GD2] Przeźroczystość PNG
deha21
post
Post #1





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

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


Witam,
Szukałem na forum i na necie informacji na ten temat, niestety żadne z podanych porad nie rozwiązało mojego problemu. Żadne imagealphablending, imagecolorallocatealpha, imagesavealpha nic nie robi. Może coś źle robię?

Mam skrypt który zmniejsza zdjęcia do podanych rozmiarów. Przy przeźroczystych plikach PNG tło zamienia się na czarne. Jak zrobić żeby tło wciąż było przeźroczyste?

Oto kod:
  1. function resize($image_file, $new_width, $new_height, $file_name, $quality){
  2. $info = getimagesize($image_file);
  3. if($info === false)
  4. return false;
  5. $img = null;
  6. switch($info[2]){
  7. case IMAGETYPE_JPEG:
  8. $img = imagecreatefromjpeg($image_file);
  9. break;
  10. case IMAGETYPE_GIF:
  11. $img = imagecreatefromgif($image_file);
  12. break;
  13. case IMAGETYPE_PNG:
  14. $img = imagecreatefrompng($image_file);
  15. break;
  16. default:
  17. return false;
  18. }
  19. $th = imagecreatetruecolor($new_width, $new_height);
  20. imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]);
  21.  
  22. switch($info[2]){
  23. case IMAGETYPE_JPEG:
  24. imagejpeg($th, $file_name.'.jpg', $quality);
  25. break;
  26. case IMAGETYPE_GIF:
  27. imagegif($th, $file_name.'.gif');
  28. break;
  29. case IMAGETYPE_PNG:
  30. imagepng($th, $file_name.'.png');
  31. break;
  32. }
  33. imagedestroy($th);
  34. imagedestroy($img);
  35. return true;
  36. }


--------------------
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 Aktualny czas: 21.08.2025 - 14:58