Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php]Pomniejszone zdjecie
Forum PHP.pl > Forum > Przedszkole
Spyder
Prosze o pomoc z tym kodem:

  1. <?php
  2. $nazwa = "Creek.jpg";
  3. $galeria = "news_pictures";
  4. $out = $galeria . "/tn" . $nazwa;
  5. $file = "news_pictures/Creek.jpg";
  6. $max_width = 300;
  7. $max_height = 100;
  8. $size = GetImageSize($file);
  9. $width = $size[0];
  10. $height = $size[1];
  11. $x_ratio = $max_width / $width;
  12. $y_ratio = $max_height / $height;
  13.  
  14. if (($width <= $max_width) && ($height <= $max_height)) {
  15.  $tn_width = $width;
  16.  $tn_height = $height;
  17. } else 
  18.  if (($x_ratio * $height) < $max_height) {
  19. $tn_height = ceil($x_ratio * $height);
  20. $tn_width = $max_width;
  21.  } else {
  22. $tn_width = ceil($y_ratio * $width);
  23. $tn_height = $max_height;
  24. }
  25.  
  26. $src = ImageCreateFromJpeg($file);
  27. $dst = ImageCreateTrueColor($tn_width,$tn_height);
  28.  
  29. ImageCopyResampled($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height);
  30.  
  31. ImageJpeg($dst, $out, 85);
  32. ImageDestroy($src);
  33. ImageDestroy($dst);
  34. chmod($galeria . "/tn" . $nazwa, 0777);
  35. ?>


Chodzi o to ze mam zdjecie na serwerze w katalogu news_pictures rozdzialka zdjecia powiedzmy 800 x 600 chodzi o to aby funkcja pobrala wielkosc zdjecia i wyswietlila pomniejszona miniaturke o max szerokosci 120 pikseli nie musi jej zapisywac na serwerze tylko wyswietlic pomniejszona w stosunku a to nie chce zadzialac questionmark.gif Czytalem inne skrypty na forum ale nie wiem jak to zrobic najprosciej.....
szawel
moze skaorzystasz z funkcji exif_thumbnail(nazwa pliku,szerokosc,wysokosc,opcjonalnie typ);
$file='costam.jpg';
exif_thumbnail($file,$width,$height,$type);
Spyder
tak ale zachowa ona proporcje jesli zdjecie bedzie np 800x800 questionmark.gif
szawel
z tego co wiem to powino bo to pobiera miniaturke z pliku jpg jesli jest zdefiniowana jakos tak to dziala...
Spyder
Chyba cos nie dziala...

  1. <?php
  2. #
  3. $file = 'test.jpg';
  4. #
  5.  
  6. #
  7. $image = exif_thumbnail($file, $width, $height, $type);
  8. #
  9.  
  10. #
  11. // width, height and type get filled with data
  12. #
  13. // after calling "exif_thumbnail"
  14. #
  15.  
  16. #
  17. if ($image) {
  18. #
  19. // send header and image data to the browser:
  20. #
  21. header('Content-type: ' .image_type_to_mime_type($type));
  22. #
  23. print $image;
  24. #
  25. }
  26. #
  27. else {
  28. #
  29. // there is no thumbnail available, handle the error:
  30. #
  31. print 'No thumbnail available';
  32. #
  33. }
  34. ?>
szawel
exif_thumbnail($file) tylko ma byc $width i $height $type sa zwracane przez funkcje sory za to ze cie wprowadzilem w blad
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.