web_master Posted June 23, 2007 Share Posted June 23, 2007 hi, my problem is: if I was upload the picture and in meantime resize itt, what can I do to dont chage the radio of the photographs if its portrait or landscape: examlpe : portrait = 600 x 800 landscape = 800 x 600 with this code will be: landscape = 800 x 600 portrait = 600 x 450 here is the code wich made the resize of picture percentagle of width or height. <?php $temporary_name = $_SERVER['DOCUMENT_ROOT']."/up_product_photo_main/temp_01.jpg"; move_uploaded_file($_FILES['product_photo']['tmp_name'][1], $temporary_name); $mimetype = $_FILES['product_photo']['type'][1]; $filesize = $_FILES['product_photo']['size'][1]; //Open the image using the imagecreatefrom..() command based on the MIME type. switch($mimetype) { case "image/jpg": case "image/jpeg": $i = imagecreatefromjpeg($temporary_name); break; case "image/gif": $i = imagecreatefromgif($temporary_name); break; case "image/png": $i = imagecreatefrompng($temporary_name); break; } //Delete the uploaded file unlink($temporary_name); //Save a copy of the original imagejpeg($i, $_SERVER['DOCUMENT_ROOT']."/up_product_photo_main/_photo_01.jpg",80); //Specify the size of the thumbnail $dest_x = 127; $dest_y = 95; //Is the original bigger than the thumbnail dimensions? if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) { //Is the width of the original bigger than the height? if (imagesx($i) >= imagesy($i)) { $thumb_x = $dest_x; $thumb_y = imagesy($i)*($dest_x/imagesx($i)); } else { $thumb_x = imagesx($i)*($dest_y/imagesy($i)); $thumb_y = $dest_y; } } else { //Using the original dimensions $thumb_x = imagesx($i); $thumb_y = imagesy($i); } //Generate a new image at the size of the thumbnail $thumb = imagecreatetruecolor($thumb_x,$thumb_y); //Copy the original image data to it using resampling imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i)); //Save the thumbnail imagejpeg($thumb, $_SERVER['DOCUMENT_ROOT']."/up_product_photo_main/photo_01.jpg", 80); unlink($_SERVER['DOCUMENT_ROOT']."/up_product_photo_main/_photo_01.jpg"); ?> Link to comment https://forums.phpfreaks.com/topic/56829-resize-landscape-and-portrait-picture/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.