Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z obrazkami
cichy19-
post 14.06.2006, 10:48:26
Post #1





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 5.06.2006

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


Witam

Mam problem z zmianą rozmiaru obrazków.
Chodzi o to, że kiedy ładuje obrazek skrypt go proporcjonalnie zmniejsza i przerabia na obrazek do formatu JPG.
Wszystko jest wporządku jeżeli ładowany obrazek jest w formacie JPG lub JPEG.
Bład pojawia się wtedy kiedy do pomniejszania zostaje załadowany obrazek formatu GIF lub PNG.

Komunikat o błedzie mówi, że format ładowanego obrazka jest niepoprawny chidzi o funkcje (imagecopyresized).

Poniżej zamieszczam kod.

Bardzo proszę o pomoc co tutaj może być nie tak.

  1. <?php
  2. function resizepics($pics, $newwidth, $newheight, $new){
  3. $x1 = $newwidth;
  4. $x2 = $newheight;
  5.  list($width, $height) = getimagesize($pics);
  6.  if($width > $height && $newheight < $height){
  7.  $newheight = $height / ($width / $newwidth);
  8.  } else if ($width < $height && $newwidth < $width) {
  9. $newwidth = $width / ($height / $newheight);  
  10.  } else {
  11.  $newwidth = $width;
  12.  $newheight = $height;
  13. }
  14. if(preg_match("/.jpg/i", "$pics")){
  15.  $source = imagecreatefromjpeg($pics);
  16. }
  17. if(preg_match("/.jpeg/i", "$pics")){
  18.  $source = imagecreatefromjpeg($pics);
  19. }
  20. if(preg_match("/.jpeg/i", "$pics")){
  21.  $source = Imagecreatefromjpeg($pics);
  22. }
  23. if(preg_match("/.png/i", "$pics")){
  24.  $source = imagecreatefrompng($pics);
  25. }
  26. if(preg_match("/.gif/i", "$pics")){
  27.  $source = imagecreatefromgif($pics);
  28. }
  29. $thumb = imagecreatetruecolor($x1, $x2);
  30. $white = imagecolorallocate($thumb,255,255,255);
  31. $x = ($x1 - $newwidth) / 2;
  32. $y = ($x2 - $newheight) / 2;
  33. imagefill($thumb, 1, 1, $white);
  34. imagecopyresized($thumb, $source, $x, $y, 0, 0, $newwidth, $newheight, $width, $height);
  35. imagejpeg($thumb, $new);
  36. if(preg_match("/.jpg/i", "$pics")){
  37.  imagejpeg($thumb, $new);
  38. }
  39. if(preg_match("/.jpeg/i", "$pics")){
  40.  imagejpeg($thumb, $new);
  41. }
  42. if(preg_match("/.jpeg/i", "$pics")){
  43.  imagejpeg($thumb, $new);
  44. }
  45. if(preg_match("/.png/i", "$pics")){
  46.  imagepng($thumb, $new);
  47. }
  48. if(preg_match("/.gif/i", "$pics")){
  49.  imagegif($thumb, $new);
  50. }
  51. }
  52. ?>
Go to the top of the page
+Quote Post
Cysiaczek
post 14.06.2006, 16:50:06
Post #2





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Cóż. Nie znam się na funkcjach graficznych php, ale proponuję sprawdzić, jakiej biblioteki GD używasz. Nie wszystkie obsługują GIF i PNG. Sprawdź w phpinfo jaką masz bibliotekę GD i poczytaj na php.net o niej.

Możliwe, że błąd jest gdzie indziej, ale na pierwszy rzut oka nie wynika z kodu winksmiley.jpg
Pozdrawiam


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
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: 20.07.2025 - 02:08