Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Zmniejszanie obrazka przestało działać
Kamil9132
post
Post #1





Grupa: Zarejestrowani
Postów: 210
Pomógł: 0
Dołączył: 7.11.2010

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


Witam
Mam taki kod:
  1. function resize_ratio($file, $new_w, $new_h, $save)
  2. {
  3. if (!is_readable($file))
  4. {
  5. return FALSE;
  6. }
  7.  
  8.  
  9.  
  10.  
  11. $info = @getimagesize($file);
  12. switch ($info['mime'])
  13. {
  14. case "image/gif":
  15. $file = imagecreatefromgif($file);
  16. break;
  17. case "image/jpeg":
  18. $file = imagecreatefromjpeg($file);
  19. break;
  20. case "image/png":
  21. $file = imagecreatefrompng($file);
  22. break;
  23. }
  24.  
  25. $old_x = imageSX($file);
  26. $old_y = imageSY($file);
  27.  
  28. $wysokosc = imagesy($file);
  29. $szerokos = imagesx($file);
  30.  
  31. echo $szerokos;
  32. echo "<br>";
  33. echo $new_w;
  34. echo "<br>";
  35.  
  36. $wpol = $szerokos/$new_w;
  37. echo "<br>";
  38.  
  39. echo $wpol;
  40.  
  41.  
  42. $nowysokosc = $wysokosc * $wpol;
  43.  
  44.  
  45. if ($old_x > $old_y)
  46. {
  47. $thumb_w=$new_w;
  48. $thumb_h=$old_y*($new_h/$old_x);
  49. }
  50.  
  51. if ($old_x < $old_y)
  52. {
  53. $thumb_w=$old_x*($new_w/$old_y);
  54. $thumb_h=$new_h;
  55. }
  56.  
  57. if ($old_x == $old_y)
  58. {
  59. $thumb_w=$new_w;
  60. $thumb_h=$new_h;
  61. }
  62.  
  63.  
  64.  
  65.  
  66. $th = ImageCreateTrueColor($thumb_w, $thumb_h);
  67. @imagecopyresampled($th, $file, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
  68. @imagejpeg($th, $save);
  69. @imagedestroy($file);
  70. @imagedestroy($th);
  71. return TRUE;
  72. }
  73.  
  74. resize_ratio("$zdjecie", "660", "$nowysokosc", "$zdjecie");


Przez chwilę działał dobrze ale potem już przestał zmieniać rozmiary zdjęcia.
Może coś przez pomyłkę usunąłem albo coś innego ale nie wiem co.
Tak czy inaczej kod nie działa sad.gif
Czemu questionmark.gif
Powód edycji: [wookieb]:
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Czekam na PW z poprawną nazwą tematu

Temat: Jak poprawnie zadac pytanie


--------------------
Go to the top of the page
+Quote Post
peter13135
post
Post #3





Grupa: Zarejestrowani
Postów: 1 447
Pomógł: 191
Dołączył: 26.03.2008

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



  1. resize_ratio("$zdjecie", "660", "$nowysokosc", "$zdjecie");

Błąd to nie jest (tzn. PHP sobie poradzi) ale tutaj nie ma potrzeby wrzucania zmiennej do stringu, podobnie z intem.

Co do problemu, gdzie jest header mówiący o tym że przesyłana treść jest obrazkiem jpg ?
Dlaczego wcześniej wyświetlasz jakieś liczby ? Zdecyduj się czy chcesz obrazek czy tekst


--------------------
:)
Go to the top of the page
+Quote Post
Kamil9132
post
Post #4





Grupa: Zarejestrowani
Postów: 210
Pomógł: 0
Dołączył: 7.11.2010

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


Zmieniłem na to:
  1. function resize_ratio($file, $new_w, $new_h, $save)
  2. {
  3. if (!is_readable($file))
  4. {
  5. return FALSE;
  6. }
  7.  
  8.  
  9.  
  10. $info = @getimagesize($file);
  11. switch ($info['mime'])
  12. {
  13. case "image/gif":
  14. $file = imagecreatefromgif($file);
  15. break;
  16. case "image/jpeg":
  17. $file = imagecreatefromjpeg($file);
  18. break;
  19. case "image/png":
  20. $file = imagecreatefrompng($file);
  21. break;
  22. }
  23.  
  24. $old_x = imageSX($file);
  25. $old_y = imageSY($file);
  26.  
  27. $wysokosc = imagesy($file);
  28. $szerokos = imagesx($file);
  29.  
  30.  
  31. $wpol = $szerokos/$new_w;
  32.  
  33.  
  34. $nowysokosc = $wysokosc * $wpol;
  35.  
  36.  
  37. if ($old_x > $old_y)
  38. {
  39. $thumb_w=$new_w;
  40. $thumb_h=$old_y*($new_h/$old_x);
  41. }
  42.  
  43. if ($old_x < $old_y)
  44. {
  45. $thumb_w=$old_x*($new_w/$old_y);
  46. $thumb_h=$new_h;
  47. }
  48.  
  49. if ($old_x == $old_y)
  50. {
  51. $thumb_w=$new_w;
  52. $thumb_h=$new_h;
  53. }
  54.  
  55.  
  56.  
  57.  
  58. $th = ImageCreateTrueColor($thumb_w, $thumb_h);
  59. @imagecopyresampled($th, $file, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
  60. @imagejpeg($th, $save);
  61. @imagedestroy($file);
  62. @imagedestroy($th);
  63. return TRUE;
  64. }
  65.  
  66. resize_ratio($zdjecie, 660, $nowysokosc, $zdjecie);


Ale nadal nie działa czemu questionmark.gif
Go to the top of the page
+Quote Post
wookieb
post
Post #5





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Dałem Ci link w którym miałaś zastosować się do wszystkich rad. Dlaczego tego nie zrobiłeś?


--------------------
Go to the top of the page
+Quote Post
Kamil9132
post
Post #6





Grupa: Zarejestrowani
Postów: 210
Pomógł: 0
Dołączył: 7.11.2010

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


Już się zastosowałem.
Dosyć dużo błędów mi pokazało ,ale tych które dotyczą właśnie tego kawałka kodu są 2:

-Notice: Undefined variable: nowysokosc in /var/www/virtual/komixxxy.cba.pl/dodawanie.php on line 407
1192

Ta linijka to jest to:
  1. resize_ratio($zdjecie, 660, $nowysokosc, $zdjecie);





-Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /var/www/virtual/komixxxy.cba.pl/dodawanie.php on line 399

A ta to jest to:
  1. $th = ImageCreateTrueColor($thumb_w, $thumb_h);


Co to oznacza questionmark.gif
Go to the top of the page
+Quote Post
kadlub
post
Post #7





Grupa: Zarejestrowani
Postów: 548
Pomógł: 105
Dołączył: 4.06.2010

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


nie masz zdefiniowanej zmiennej $nowysokosc
pokaż kod gdzie wywołujesz tą funkcje
Go to the top of the page
+Quote Post
Kamil9132
post
Post #8





Grupa: Zarejestrowani
Postów: 210
Pomógł: 0
Dołączył: 7.11.2010

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


Zmienną $nowysokosc mam zdefiniowaną tutaj:
  1. $wysokosc = imagesy($file);
  2. $szerokos = imagesx($file);
  3.  
  4.  
  5. $wpol = $szerokos/$new_w;
  6.  
  7.  
  8. $nowysokoscs = $wysokosc * $wpol;
  9. $nowysokosc = round($nowysokoscs);


A funkcje wywołuje tutaj:
  1. resize_ratio($zdjecie, 660, $nowysokosc, $zdjecie);


Pomoże ktoś questionmark.gif





EDIT: Szkoda że nikt nie odpowiedział sad.gif
Ale znalazłem samemu błąd smile.gif
Temat do zaknięcia.

Ten post edytował Kamil9132 3.04.2011, 12:29:48
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 Aktualny czas: 21.08.2025 - 01:08