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 1043 korisnika na forumu :: 100 registrovanih, 8 sakrivenih i 935 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 20624 - dana 04 Apr 2026 04:18

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: 10x10.9, ALEXV, amaterSRB, Asteker, BB, Bo96, Bojan198527, bokisha253, brandža84, branko7, brufen, casual03, Cicumile, cikadeda, comi_pfc, Comyymoc, cvrle312, dane007, darcaud, darios, dekiz, dendrit86, despodovski.s, Dimitrise93, djonsule, Dovla 1980, Ercomero, Fabius, Folkstar, Futurama, g_g, GH69, Giskard, glados, Hemi, HrcAk47, Ikica977, Jakonjveliki, Jose, Jozo74, Kajzer Soze, Kruger, lcc, Marko1238, Marko43, MarkoDzimi, MarkoW, marsi, mean_machine, mercedesamg, Milan1996, milenko crazy north, Miler88, MILO-VAN, Mimis82, mishkooo, MK10, mkukoleca, monomah, mrzimregistraciju, Nole, orfanel, Otto Grunf, Pale2025, Panter, Pekman, Petar888, picknick, ping15, Prečanin30, Qvazimodo, RajkoB, Ripanjac, rovac, SD izvidjac, septembar, Sharpshooter, Sitan_Lopov, skok, Smiljkovich, Smor, Solunac na steroidima, Spila 0405, Srky Boy, Stoorb, tomo2, tooljan, TRZH92, umpah-pah, v82, VanZan, Vlada1389, VladaKG1980, Vladko, vrgudinac, vukdra, vukovi, xAlex2, zivojin32, zmajbre