Image resize, potrebna pomoć

Image resize, potrebna pomoć

offline
  • Pridružio: 30 Avg 2008
  • Poruke: 91

Napisano: 27 Mar 2011 13:05

Pozdrav imam scriptu koja uploaduje slike u novi folder, kako mogu da izmenim dimenzije slika na 300 širine i 200 visine
$id = '1'; $i = '0'; // End Filter Function -------------------------------------------------------------- include_once "scripts/connect_to_mysql.php"; // Add the updated info into the database table while(list($key,$value) = each($_FILES['images']['name']))       {          if(!empty($value))          {             $filename = $value;                $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line                if (!is_dir("images/$id"))                mkdir("images/$id", 0777);                $i++;                $add = "images/$id/$i.jpg";                                                                        //echo $_FILES['images']['type'][$key];               // echo "<br>";                copy($_FILES['images']['tmp_name'][$key], $add);                chmod("$add",0777);                    }       }   

Još da dodam da mi izbacuje gršku
Warning: Variable passed to each() is not an array or object koja se odnosi na ovaj red
each($_FILES['images']['name'])), u suštini zadatak odradi

Dopuna: 27 Mar 2011 16:21

Rešio sam problem na drugi način evo koda ako nekome zatreba

<?php function imgReisize($uploadedfile, $Destination, $Thumb){ //this is the function that will resize and copy our images // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=300; $newheight=($height/$width)*300; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = $Destination; imagejpeg($tmp,$filename,100); // For our purposes, I have resized the image to be // 150 pixels high, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max height other than // 150, simply change the $newheight variable $newheight=100; $newwidth=($width/$height)*90; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = $Thumb; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. echo "Successfully Uploaded: <img src='".$filename."'>"; }     if(isset($_POST['submit'])){      $imgNumb=1; //This the "pointer" to images      $DestinationDir="./imgs/";  //Place the destination dir here      $ThumbDir="./imgs/thumbs/";  //Place the thumb dir here        while($_FILES['img'.$imgNumb]['tmp_name']){               $Unique=microtime(); // We want unique names, right?               $destination=$DestinationDir.md5($Unique).".jpg";               $thumb=$ThumbDir.md5($Unique).".jpg";               imgReisize($_FILES["img".$imgNumb]['tmp_name'], $destination, $thumb);               $imgNumb++;        }     } ?>



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 1976 korisnika na forumu :: 103 registrovanih, 7 sakrivenih i 1866 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 6018 - dana 19 Dec 2025 13:41

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: accordionist, ALEKSICMILE, aleph_one, AMCXXL, Ares12356, Arhiv, Arsenije, Automaticar, babaroga, Beardonitch, Betta, Betty25, bigfoot, Bivan, Bobrock1, bokisha253, Bole72, Boris.A, Boris90, BORUTUS, branko7, BWG, ccoogg123, coaaco, darkojovxp, Dejan_vw, DrMrPr, due, dule10savic, dulleo, ElGenius, geo.dule, ginjica, Goldman, GreenMan, Halabit, havoc995, HrcAk47, iceburn, Ilija Cvorovic, Istman, Jakonjveliki, Joint Chief, Još malo pa deda, Kazablankasrb, Kenanjoz, kikisp, kunktator, ljuba, loon123, lukac, m0nstrum_, max power, MDrasko, miki kv, Miki01, mikrimaus, milivoje_vatrogasac, MiloradKomadic, Milos1389, Mis uz pusku, mkukoleca, Mrav Obrad, nazgul75, nebidrag, Nikolajevic, NoOneEver Dreams, Papadubi, Pavel Medved, pavle_pzs, pein, Pero Petković, Petarvu, pobeda, Polifon, Povratak1912, Regrut Boskica, savaskytec, Shilok, simicnenadbg, Sinduk, Sitan_Lopov, Smiljkovich, Srki94, Srna, Stacka, stefan95, stibium51, t84dar, tm, tuja, USSVoyager, Utd4ce, VaRvArI 85, veljkovicdani, vespa nikola, vidra1, VJ, Voice1, Volkhov-M, Vrač, wizzardone, Zoca