Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Jak wygenerować miniaturkę z pliku PNG?
pehaperowiec
post 6.01.2014, 10:39:08
Post #1





Grupa: Zarejestrowani
Postów: 91
Pomógł: 8
Dołączył: 26.09.2011

Ostrzeżenie: (10%)
X----


Napisałem taki kod do generowania miniaturek z pliku jpg, gif oraz png
  1. <?php
  2.  
  3. if(isset($_FILES['img_main']['tmp_name']) && is_uploaded_file($_FILES['img_main']['tmp_name'])) {
  4. if($_FILES['img_main']['type']=="image/png" || $_FILES['img_main']['type']=="image/jpeg" || $_FILES['img_main']['type']=="image/gif") {
  5. move_uploaded_file($_FILES['img_main']['tmp_name'], "../gal/".$tab['gallery_name']."/".$_FILES['img_main']['name']);
  6.  
  7. $img_path="../gal/".$tab['gallery_name']."/".$_FILES['img_main']['name'];
  8. $thumb_path="../gal/".$tab['gallery_name']."/thumbs/".$_FILES['img_main']['name'];
  9. $max_width=$max_height=100;
  10. $img_attr = getimagesize($img_path);
  11. if($img_attr[0]>$img_attr[1]){
  12. $scale = $img_attr[0] / $max_width;
  13. }else{
  14. $scale = $img_attr[1] / $max_height;
  15. }
  16. $w = floor($img_attr[0]/$scale);
  17. $h = floor($img_attr[1]/$scale);
  18. $thumb = imagecreatetruecolor($w,$h);
  19. switch($_FILES['img_main']['type']) {
  20. case "image/jpeg": {
  21. imagecopyresampled($thumb, imagecreatefromjpeg($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
  22. imagejpeg($thumb,$thumb_path,85);
  23. break;
  24. }
  25. case "image/png": {
  26. imagecopyresampled($thumb, imagecreatefrompng($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
  27. //header('Content-type: image/png');
  28. imagepng($thumb,$thumb_path,85);
  29. break;
  30. }
  31. case "image/gif": {
  32. imagecopyresampled($thumb, imagecreatefromgif($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
  33. imagegif($thumb,$thumb_path,85);
  34. break;
  35. }
  36. }
  37. }
  38. }
  39.  
  40. ?>
Jednak przy próbie generacji miniaturki PNG zwraca błąd:
Kod
Warning: imagepng() [function.imagepng]: gd-png error: compression level must be 0 through 9 in D:\wamp\www\class\class_admin.php on line 289
Linia 289 to:
  1. imagepng($thumb,$thumb_path,85);
Dodatkowo WampSerwer się "wykrzacza" podczas tej operacji. Czy ktoś ma na to jakiś pomysł?
Go to the top of the page
+Quote Post
Kshyhoo
post 6.01.2014, 10:47:00
Post #2





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Manual:
Cytat
quality

Compression level: from 0 (no compression) to 9.


--------------------
Go to the top of the page
+Quote Post
pehaperowiec
post 6.01.2014, 10:48:08
Post #3





Grupa: Zarejestrowani
Postów: 91
Pomógł: 8
Dołączył: 26.09.2011

Ostrzeżenie: (10%)
X----


Zgadza się. Dziekuje za pomoc
Go to the top of the page
+Quote Post

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: 13.08.2025 - 22:53