Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Miniaturki:)
wozniak
post
Post #1





Grupa: Zarejestrowani
Postów: 278
Pomógł: 0
Dołączył: 21.11.2003

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


Witam, mam skrypcik do robienia miniaturek tylko z formularza ida 3 zdjecia i teraz mam pytanie musze powielic ten kod 3 razy i zmienic nazwe zmiennych czy moze jest jakis inny sposob?
Skrypt:
  1. <?php
  2. $pic = $_FILES['userfile']['tmp_name'];
  3.  
  4.  $jpegImg = imageCreateFromJPEG($pic);
  5.  
  6. unlink($pic);
  7.  
  8.  $imgsizex = imageSX($jpegImg);
  9.  $imgsizey = imageSY($jpegImg);
  10.  
  11. $jpegImg_small = imagecreatetruecolor(160, 160);
  12.  
  13. if ($imgsizex <> $imgsizey) {
  14.  
  15. if ($imgsizex > 160 OR $imgsizey > 160) {
  16.  
  17. if ($imgsizex < $imgsizey) {
  18.  
  19. $ax = $imgsizex / 160;
  20. $axs = (integer) $ax;
  21. $axr = 160 * $axs + ($imgsizex - 160 * $axs);
  22. $ayr = 160 * $axs + ($imgsizex - 160 * $axs);
  23.  
  24. } else {
  25.  
  26. $ay = $imgsizey / 160;
  27. $ays = (integer) $ay;
  28. $ayr = 160 * $ays + ($imgsizey - 160 * $ays);
  29. $axr = 160 * $ays + ($imgsizey - 160 * $ays);
  30.  
  31. }
  32.  
  33. $jpegImg_dst = imagecreatetruecolor($axr, $ayr);
  34. imagecopymerge($jpegImg_dst, $jpegImg, 0, 0, 0, 0, $axr, $ayr, 100);
  35. $imgsizex = $axr;
  36. $imgsizey = $ayr;
  37.  
  38. } else {
  39.  
  40. $jpegImg_dst = $jpegImg;
  41.  
  42. }
  43.  
  44. } else {
  45.  
  46. $jpegImg_dst = $jpegImg;
  47.  
  48. }
  49.  
  50. imagecopyresampled($jpegImg_small, $jpegImg_dst, 0, 0, 0, 0,
  51.  160, 160, $imgsizex, $imgsizey);
  52.  
  53. $resizedfilename = substr(ereg_replace("[^A-Za-z0-9]", "", 
  54. crypt(time())) .
  55.  ereg_replace("[^A-Za-z0-9]", "", crypt(time())) .
  56.  ereg_replace("[^A-Za-z0-9]", "", crypt(time())),
  57.  0, 8);
  58.  
  59.  $dirtosaveresized = getcwd()."/grafika/".$resizedfilename.".jpg";
  60.  
  61.  ImageJPEG($jpegImg_small, $dirtosaveresized, 65);
  62. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wozniak
post
Post #2





Grupa: Zarejestrowani
Postów: 278
Pomógł: 0
Dołączył: 21.11.2003

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


No dobra czyli skrypt mam tak:
  1. <?php
  2. function mini(){
  3. gloabl $userfile;
  4.  $pic = $_FILES['userfile']['tmp_name'];
  5.  
  6.  $jpegImg = imageCreateFromJPEG($pic);
  7.  
  8. unlink($pic);
  9.  
  10.  $imgsizex = imageSX($jpegImg);
  11.  $imgsizey = imageSY($jpegImg);
  12.  
  13. $jpegImg_small = imagecreatetruecolor(160, 160);
  14.  
  15. if ($imgsizex <> $imgsizey) {
  16.  
  17. if ($imgsizex > 160 OR $imgsizey > 160) {
  18.  
  19. if ($imgsizex < $imgsizey) {
  20.  
  21. $ax = $imgsizex / 160;
  22. $axs = (integer) $ax;
  23. $axr = 160 * $axs + ($imgsizex - 160 * $axs);
  24. $ayr = 160 * $axs + ($imgsizex - 160 * $axs);
  25.  
  26. } else {
  27.  
  28. $ay = $imgsizey / 160;
  29. $ays = (integer) $ay;
  30. $ayr = 160 * $ays + ($imgsizey - 160 * $ays);
  31. $axr = 160 * $ays + ($imgsizey - 160 * $ays);
  32.  
  33. }
  34.  
  35. $jpegImg_dst = imagecreatetruecolor($axr, $ayr);
  36. imagecopymerge($jpegImg_dst, $jpegImg, 0, 0, 0, 0, $axr, $ayr, 100);
  37. $imgsizex = $axr;
  38. $imgsizey = $ayr;
  39.  
  40. } else {
  41.  
  42. $jpegImg_dst = $jpegImg;
  43.  
  44. }
  45.  
  46. } else {
  47.  
  48. $jpegImg_dst = $jpegImg;
  49.  
  50. }
  51.  
  52. imagecopyresampled($jpegImg_small, $jpegImg_dst, 0, 0, 0, 0,
  53.  160, 160, $imgsizex, $imgsizey);
  54.  
  55. $resizedfilename = substr(ereg_replace("[^A-Za-z0-9]", "", 
  56. crypt(time())) .
  57.  ereg_replace("[^A-Za-z0-9]", "", crypt(time())) .
  58.  ereg_replace("[^A-Za-z0-9]", "", crypt(time())),
  59.  0, 8);
  60.  
  61.  $dirtosaveresized = getcwd()."/grafika/".$resizedfilename.".jpg";
  62.  
  63.  ImageJPEG($jpegImg_small, $dirtosaveresized, 65);
  64. }
  65.  
  66. ?>

i teraz wywołuje :
  1. <?php
  2.  
  3. mini(); // tylko jak tutaj podpiac ze $userfile="cos";
  4.  
  5. ?>
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: 3.10.2025 - 06:19