Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z pomniejszeniem obrazka .png - biblioteka GD
Michael65
post
Post #1





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 2.04.2010

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


Witam,

mam kod:

  1. <?php
  2.  
  3.  
  4. $filename = 'index_07.png';
  5. $percent = 0.5;
  6.  
  7. // Content type
  8. header('Content-Type: image/png');
  9.  
  10. // Get new dimensions
  11. list($width, $height) = getimagesize($filename);
  12. $new_width = $width * $percent;
  13. $new_height = $height * $percent;
  14.  
  15. // Resample
  16. $image_p = imagecreatetruecolor($new_width, $new_height);
  17. $image = imagecreatefrompng($filename);
  18. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  19.  
  20. // Output
  21. imagepng($image_p, null, 100);
  22.  
  23.  
  24.  
  25. ?>


i on nie działa, nie wiem dlaczego.

Dodam, że gdy robię identyczny kod tylko dla formatu .jpg to działa wyśmienicie.

  1. <?php
  2.  
  3.  
  4. $filename = 'index_02.jpg';
  5. $percent = 0.5;
  6.  
  7. // Content type
  8. header('Content-Type: image/jpeg');
  9.  
  10. // Get new dimensions
  11. list($width, $height) = getimagesize($filename);
  12. $new_width = $width * $percent;
  13. $new_height = $height * $percent;
  14.  
  15. // Resample
  16. $image_p = imagecreatetruecolor($new_width, $new_height);
  17. $image = imagecreatefromjpeg($filename);
  18. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  19.  
  20. // Output
  21. imagejpeg($image_p, null, 100);
  22.  
  23.  
  24.  
  25. ?>


Dlaczego z .png się nie udaje?

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: 22.08.2025 - 22:16