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
 
Start new topic
Odpowiedzi
Mrokodajny
post
Post #2





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 13.02.2012

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


Mam następującą prościutką funkcyjkę resajzującą wyłącznie gify i jest tak problem bo pojawia się czarne tło i nie wiem o co chodzi:


  1. function resize($image_file, $new_width, $new_height, $file_name)
  2. {
  3. $img = imagecreatefromgif($image_file);
  4. $x=imagesx($img);
  5. $y=imagesy($img);
  6. $th = imagecreatetruecolor($new_width, $new_height);
  7. imagealphablending($th, true);
  8. imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $x, $y);
  9. imagegif($th, $file_name);
  10. imagedestroy($th);
  11. imagedestroy($img);
  12. return true;
  13. }
  14.  

uprzejmie proszę o pomoc co źle robię
z góry dziękuję za pomoc

Ten post edytował Mrokodajny 6.05.2017, 20:45:07
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 8.10.2025 - 08:52