Forum Moderators: coopster
// Ratios
$image_ratio = $size[0] / $size[1]; // Actual image's ratio
$destination_ratio = 560 / 560; // Ratio of dest. placeholder
// Taller
if($image_ratio < $destination_ratio)
{
//Too tall:
if($height > $max_height)
{
$height = $max_height;
$width = ceil($height / $image_ratio);
}
}
// Wider / balanced & too wide:
else if ($width > $max_width)
{
$width = $max_width;
$height = ceil($width / $image_ratio);
}
Throwing a dart I would say the following should be an 'if', not an 'else if' - as written, if the height is adjusted, the width will never be tested, because you have qualified for the 'if', so the 'else if' is ignored. Beyond there you will have to post more on how your variables are defined.
else if ($width > $max_width)
{
$width = $max_width;
$height = ceil($width / $image_ratio);
}
Justin
$image_ratio = $size[0] / $size[1]; // Actual image's ratio
... you may use something like:
$size = GetImageSize( $destination ); ... see below:
// START - THIS CODE INSERTS OR UPDATES ANY IMAGE
$originalFile = $HTTP_POST_FILES['userfile']['name']; // the name of the chosen file
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { // was the file uploaded to the temp folder?
$pathToImagesFolder = IMAGESFOLDER . "/"; // set the path to the images folder
$destination = $pathToImagesFolder . $originalFile; // join the path and filename together
if(move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $destination)) { // move the file to the destination
// retrieve the image parameters
$size = GetImageSize( $destination );
$imagewidth = $size[0];
$imageheight = $size[1];
$imageext = $size[2]; // $HTTP_POST_FILES['userfile']['type']; used instead
$imageSource = $size[3];
$userfile_size = $HTTP_POST_FILES['userfile']['size'];
// impose the image restrictions - for PHP versions less than 4.2.0 - start
... and so on... there's a lot more code to the image handling, you can download it free at phpYellow.com look for phpYellow Lite Edition and then unzip and look for image*.php in the root of the unzipped folder, with the above code from images_upload.php
Globalissa