Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] thumbnail obrazka - problem
Forum PHP.pl > Forum > Przedszkole
bastek8989
witam

Mam pewien problem odnosnie thumbnail obrazka:
polega on na tym, ze ustawiam rozmiar 99x59 a thumb robi sie na szerokosc 59 lecz zeby zachowac proporcje wystaje znacznie poza okreslona wysokosc 59 i w ten sposob strona mi sie moze rozjechac.

i tu pytanie:

Da sie to jakos obejsc te proporcje?
Zeby skrypt bral pod uwage ze ma do dyspozycji 59x99 i wg tego ustalal proporcjonalny obrazek?


prosze o pomoc
pozdrawiam
maryaan
a ten... widzisz tu gdizesz wrozke? moze bys wkleil ten skrypt ktory ma robic miniature? blinksmiley.gif
bastek8989
pytam jak a nie szukam bledu - sam sobie zastosuje sposob
eS...
  1. <?php
  2. function scale($img,$maxwidth,$maxheight) { 
  3. $imginfo = getimagesize($img); 
  4. $imgwidth = $imginfo[0]; 
  5. $imgheight = $imginfo[1]; 
  6. if ($imgwidth > $maxwidth) { 
  7. $ration = $maxwidth/$imgwidth; 
  8. $newwidth = round($imgwidth*$ration); 
  9. $newheight = round($imgheight*$ration); 
  10. if ($newheight > $maxheight) { 
  11. $ration = $maxheight/$newheight; 
  12. $newwidth = round($newwidth*$ration); 
  13. $newheight = round($newheight*$ration); 
  14. return array("image" => $img, "width" => $newwidth, "height" => $newheight); 
  15. } else { 
  16. return array("image" => $img, "width" => $newwidth, "height" => $newheight); 
  17. } 
  18. } else if ($imgheight > $maxheight) { 
  19. $ration = $maxheight/$imgheight; 
  20. $newwidth = round($imgwidth*$ration); 
  21. $newheight = round($imgheight*$ration); 
  22. if ($newwidth > $maxwidth) { 
  23. $ration = $maxwidth/$newwidth; 
  24. $newwidth = round($newwidth*$ration); 
  25. $newheight = round($newheight*$ration); 
  26. return array("image" => $img, "width" => $newwidth, "height" => $newheight); 
  27. } else { 
  28. return array("image" => $img, "width" => $newwidth, "height" => $newheight); 
  29. } 
  30. } else { 
  31. return array("image" => $img, "width" => $imgwidth, "height" => $imgheight); 
  32. } 
  33. }
  34. ?>

$maxwidth i $maxheight i po sprawie
bastek8989
to co widze nierozwiazuje problemu (z tego co widze - nie sprawdzalem)

sam sobie zrobilem dzialanie, mzoe komus sie przyda..


$newwidth = round($newwidth*$ration);
$newheight = round($newheight*$ration);

== u mnie jest

$new_x = $image_x*$ratio_x;
$new_y = $image_y*$ratio_y;

to nie zalatwia sprawy

wystarczy:

$h = $new_y - $max_h;
$new_x = $new_x - $h;
$new_y = $new_y - $h;

tego mi brakowalo - teraz juz nie mam problemu z uciekaniem za wskazany H
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.