Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Generowanie miniatur obrazkow
djbarca
post
Post #1





Grupa: Zarejestrowani
Postów: 231
Pomógł: 1
Dołączył: 22.04.2007
Skąd: Rypin

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


Mam takie pytanie: jak tworzyc miniatury obrazkow w php. Lecz nie chodzi o to zeby miniatura miala np 400x400 i koniec tylko zeby zmieniala sie wielkosc proporcjonalnie. zeby w trakcie uploadowania obrazka automatycznie tworzylo obrazek proporcjonalnie pomiejszony do oryginalnego w nowym folderze moglby mi ktos pomoc (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ? (np obrazek ma 500x1000 jak podaje w input ile ma byc szerokosc (np 100 ) i tworzy ta miniature tutaj :100x200 )) wtedy ja n newsach bede mogl zrobic cos takiedo



<a href=obrazki/obraz1_duzy.jpg><img src=miniatury/obraz1_maly.jpg></a>

Ten post edytował djbarca 30.08.2007, 11:56:38
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
djbarca
post
Post #2





Grupa: Zarejestrowani
Postów: 231
Pomógł: 1
Dołączył: 22.04.2007
Skąd: Rypin

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


zrobilem to (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)


  1. <?php
  2. print '<form enctype="multipart/form-data" action="upload_img.php?cmd=upload" method="POST">';
  3. print '<input type="hidden" name="MAX_FILE_SIZE" value="999999" />';
  4. print '<font size=1>Uploaduj Obrazek do newsa!';
  5. print '<br><input name="userfile" class=button  type="file" />
  6. <input type=text class=button name=szerokosc>Szerokosc<br>';
  7. print '<input type="submit" value="Uploaduj" class=button />';
  8. print '</form>';
  9.  
  10. if ($cmd=='upload') {
  11. if ($szerokosc) {
  12. $location = '../grafika/news/' . basename($_FILES['userfile']['name']);
  13. $nazwa = '' . basename($_FILES['userfile']['name']);
  14.  
  15. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $location)) {
  16.  
  17.  
  18.  
  19. $zrodlo=$location;
  20. $imgSrc=imagecreatefromjpeg("$zrodlo");
  21. $srcWidth=imagesx($imgSrc);
  22. $srcHeight=imagesy($imgSrc);
  23.  
  24.  
  25. $outWidth=$szerokosc;
  26. $proporcja=$srcWidth/$szerokosc;
  27. $outHeight=$srcHeight/$proporcja;
  28.  
  29.  
  30. $imgOut=imagecreatetruecolor($outWidth,$outHeight);
  31. imagerectangle($imgOut,0,0,$outWidth,$outHeight,
  32.  imagecolorallocate($imgOut,0,0,0));
  33.  
  34. $dx=0; $dy=0; $dw=$outWidth; $dh=$outHeight;
  35. if ($outWidth*$srcHeight!=$outHeight*$srcWidth) { 
  36.  
  37.  if ($srcWidth>$srcHeight) { 
  38. $dw=$outWidth;
  39. $dh=($dw*$srcHeight)/$srcWidth;
  40. $dy=($outHeight-$dh)/2;
  41.  }
  42.  else { 
  43. $dh=$outHeight;
  44. $dw=($dh*$srcWidth)/$srcHeight;
  45. $dx=($outWidth-$dw)/2;
  46.  }
  47. }
  48. imagecopyresampled($imgOut,$imgSrc,$dx,$dy,0,0,
  49.  $dw,$dh,$srcWidth,$srcHeight); 
  50. imagepng($imgOut,"../grafika/miniatury/$nazwa");
  51. imagedestroy($imgSrc);
  52. imagedestroy($imgOut);
  53.  
  54. print "<font color=red>$nazwa</font> zostal zaladowany poprawnie <br>";
  55. print "<b>Obraz:</b>$srcWidth X $srcHeight<br>";
  56. print "<b>Miniatura:</b>$outWidth X $outHeight";
  57. } else { echo "Obraz newsa nie został załadowany..."; } 
  58.  
  59. }
  60. }
  61. ?>


o cos takiego mi chodzilo (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował djbarca 4.09.2007, 08:11:23
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 13:09