Jump to content

resize landscape and portrait picture


web_master

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.