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 990 korisnika na forumu :: 95 registrovanih, 12 sakrivenih i 883 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: 015, 100jan, A.R.Chafee.Jr., alternator, Armadillo, Automaticar, B61, babaroga, bigbear, bigfoot, bojank, bojanM84, bokisha253, Borej, Boris BM, bozo13, ccoogg123, CikaKURE, Clouseau, cojapop, draganl, dukajov, Dvvest, ElGenius, galerija, Georgius, ginjica, iceburn, Igritelj, ILGromovnik, ivan1973, jackreacher011011, jalos, Jeremiah, Jose, Krusarac, kybonacci, lafa008, laurusri, ljuba.b, Lošmi, Mackomen, mango, Manjane, maxim_von_burdengate, mercedesamg, Mercury, Miki 24pbr, milikonst, minmatar34957, mkukoleca, moldway, Mrav Obrad, nebidrag, nebkv, obsc, OtacMakarije, Parker, perunnurep, pirke96, pisac12, Polifon, Povratak1912, PrincipL, proka89, pzqmal, S-lash, SamostalniReferent, saputnik plavetnila, sasa87, shota91, Sir Budimir, skvara, stagezin, starlights, Stoilkovic, synergia, TalicniTom, Tas011, tihi-posmatrac, Toper, Trpe Grozni, Username1000, varda, vathra, Vatreni Zmaj, Vlada78, vladas87, vukan0799, W123, wolf431, Zavulon, zax22r, Zoca, zoran77