Search the Community
Showing results for tags 'scale'.
-
i have this code which will resize the uploaded image to its max level. all i want is to transfer my images into a folder if i will use this format move_uploaded_file($_FILES['image']['tmp_name'],'uploads/'. $_FILES['image']['name']); only one image will be place on the folder and its the original image. move_uploaded_file($_FILES['image']['tmp_name'],$_FILES['image']['name']); if i will used this code all resize images will be displayed but not in the folder which i want the image to be place upload_image.php
- 1 reply
-
- upload images
- php
-
(and 3 more)
Tagged with:
-
I found a script that resizes all images in a given directory to a new size. I need some guidance to modify this script to my needs. The script resizes images to a specified image width and height. I would like to change that to make it scale the image to half the original size if it is above a certain size. I would also like for it to create a new image of a given size of 150px * 150px [icons]. How can I achieve this? <?php //Maximize script execution time ini_set('max_execution_time', 0); //Initial settings, Just specify Source and Destination Image folder. $ImagesDirectory = 'images/gallery/'; //Source Image Directory End with Slash $DestImagesDirectory = 'images/main/'; //Destination Image Directory End with Slash $NewImageWidth = 500; //New Width of Image $NewImageHeight = 500; // New Height of Image $Quality = 80; //Image Quality //Open Source Image directory, loop through each Image and resize it. if($dir = opendir($ImagesDirectory)){ while(($file = readdir($dir))!== false){ $imagePath = $ImagesDirectory.$file; $destPath = $DestImagesDirectory.$file; $checkValidImage = @getimagesize($imagePath); if(file_exists($imagePath) && $checkValidImage) //Continue only if 2 given parameters are true { //Image looks valid, resize. if(resizeImage($imagePath,$destPath,$NewImageWidth,$NewImageHeight,$Quality)) { echo $file.' resize Success!<br />'; /* Now Image is resized, may be save information in database? */ }else{ echo $file.' resize Failed!<br />'; } } } closedir($dir); } //Function that resizes image. function resizeImage($SrcImage,$DestImage, $MaxWidth,$MaxHeight,$Quality) { list($iWidth,$iHeight,$type) = getimagesize($SrcImage); $ImageScale = min($MaxWidth/$iWidth, $MaxHeight/$iHeight); $NewWidth = ceil($ImageScale*$iWidth); $NewHeight = ceil($ImageScale*$iHeight); $NewCanves = imagecreatetruecolor($NewWidth, $NewHeight); switch(strtolower(image_type_to_mime_type($type))) { case 'image/jpeg': case 'image/png': case 'image/gif': $NewImage = imagecreatefromjpeg($SrcImage); break; default: return false; } // Resize Image if(imagecopyresampled($NewCanves, $NewImage,0, 0, 0, 0, $NewWidth, $NewHeight, $iWidth, $iHeight)) { // copy file if(imagejpeg($NewCanves,$DestImage,$Quality)) { imagedestroy($NewCanves); return true; } } } ?>