Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: miniatury obrazków
Forum PHP.pl > Forum > Przedszkole
Superhero
chciałbym zrobić coś takiego, że uploaduje jakieś zdjęcie a strona w php 'robi' jego miniaturę, zapisuje ją a pierwotne zdjęcie usuwa, żeby nie zajmowało miejsca. czy jest to mozliwe?
vala
mozliwe
poszukaj sobie tu odpowiedniej klasy : http://www.phpclasses.org/
gu35t
tak. tu masz 2 skrypty.tylko sobie je dostosuj.
  1. <?
  2. function resize($im_file_name){
  3. $image_attribs = getimagesize($im_file_name); 
  4. $im_old = imageCreateFromJpeg($im_file_name);
  5. $th_max_width = 120;
  6. $th_max_height = 120; 
  7. if($image_attribs[0]>=$image_attribs[1]){
  8.  @$ratio = ($width >= $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1]; 
  9.  }
  10.  else{
  11. @$ratio = ($width < $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1];
  12. }
  13. $th_width = $image_attribs[0] * $ratio;
  14. $th_height = $image_attribs[1] * $ratio;
  15. $im_new = imagecreatetruecolor($th_width,$th_height);
  16. $th_file_name = strrchr($im_file_name, &#092;"/\");
  17. $th_file_name = substr($im_file_name, 0 , strlen($im_file_name)-4) . '-thumb.jpg';
  18. imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
  19. imageJpeg($im_new, $th_file_name ,80);
  20. }
  21. ?>


  1. <?
  2. $filejpg= './images/' . $_POST['dzial'] . '/' . date(&#092;"mdYHis\") . '.jpg';
  3. if(move_uploaded_file($_FILES['plik']['tmp_name'], $filejpg)){
  4. $f = fopen($filetext, &#092;"w+\");
  5. fputs($f, htmlspecialchars($_POST['cena']) . &#092;"n\");
  6. fputs($f, date(&#092;"mdYHis\"));
  7. fclose($f);
  8. resize($filejpg);
  9. print &#092;"zaladowano\";
  10.  
  11. }
  12. ?>
Superhero
Cytat(gu35t @ 2005-06-23 06:24:11)
tak. tu masz 2 skrypty.tylko sobie je dostosuj.

jeszcze tylko poprosze o wyjasnienie co robi pierwszy skypt a co drugi, w jakiej kolejnosci je uruchamiac i czy moga byc uruchamiane jeden po prugim.
vala
2 skrypt to uploader
najpierw chciales wrzucac czyli upload a potem przycinac?

1 skrypt to przycinanie
definiujesz sobie
$th_max_width = 120;
$th_max_height = 120;

a nastepnie odpalasz go zaraz po uploadowaniu podajac jako parametr nazwe pliku
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.