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 1088 korisnika na forumu :: 44 registrovanih, 7 sakrivenih i 1037 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: A.R.Chafee.Jr., Apok, bojanM84, bokisha253, Boris BM, crnitrn, d bos, Dannyboy, debeli, Denaya, Djokislav, Dorcolac, dushan, FOX, gasha, ikan, Karla, Lucije Kvint, maiden6657, Marko Marković, mercedesamg, Mercury, Metanoja, MiG-29M2, milanovic, Milos ZA, mnn2, mocnijogurt, ObelixSRB, operniki, radoznao, raptorsi, sevenino, Singidunumac, sokars, SR-3m, Srle993, Sumadija34, vathra, vladulns, x9, yufighter, Zimbabwe, šumar bk2