...

View Full Version : problem with image uploader/resizer



a|landargin
02-15-2003, 01:31 PM
hi, i have a problem with my image uploader/reziser

it generates a thumbnail and a larger one, that can also be rezised.

my problem is: this is only suitable for images that are originally larger than the thumbnail. because in case that they are smaller they become stretched when the tumbnail is generated.

so i need a part in the script that checks if the original is smaller then the values chosen for thumbnails. and if this is true, it should not rezise the thumbnail.
here comes the code



function gmfilename($uplfile_name, $filename, $extension)
...

if($extension == jpg)
{
if(function_exists(imagejpeg) && $chk[1] == 1)
{
$imgptr = imagecreatefromjpeg("$sourcefile");
if($imgptr)
{
imggetsize($imgptr, &$x, &$y);
imgnewsize($x, $y, &$newx, &$newy);
if(function_exists(imagecreatetruecolor) && $gdversion == 2)
{
$destptr = imagecreatetruecolor($newx, $newy);
}
else
{
$destptr = imagecreate($newx, $newy);
}
imagecopyresized($destptr, $imgptr, 0, 0, 0, 0, $newx, $newy, $x, $y);
imagejpeg($destptr, $sourcefile, $quality);
imagedestroy($imgptr);
imagedestroy($destptr);
}
else
{
echo "$msg[53]";
}
}
else
{
echo "$msg[54]";
}
}
.... }
else
{
$destptr = imagecreate($newx, $newy);
}
imagecopyresized($destptr, $imgptr, 0, 0, 0, 0, $newx, $newy, $x, $y);
imagepng($destptr, $sourcefile, $quality);
...

function imggetsize($imgptr, $x, $y)
{
$x = imagesx($imgptr);
$y = imagesy($imgptr);
}

function imgnewsize($x, $y, $newx, $newy)
{
global $resizemode;

if($resizemode == 1)
{
if($x > $y)
{
$verh = $x / $y;
$newy = $newx / $verh;
}
else
{
$verh = $y / $x;
$newy = $newx * $verh;
}
}
elseif($resizemode == 2)
{
if($x > $y)
{
$verh = $x / $y;
$newx = $newy * $verh;
}
else
{
$verh = $y / $x;
$newx = $newy / $verh;
}
}
}...


thanx for your answers!

GoHF
02-17-2003, 01:19 AM
Dunno where are your "values chosen for thumbnail", but I created some just to examplify:



$valueForThumbnailX = 80;
$valueForThumbnailY = 80;

imggetsize($imgptr, &$x, &$y);

if ($x < $valueForThumbnailX && $y < $valueForThumbnailY){
$newx = $x;
$newy = $y;
}else{
newImageSize(...)
}



was this what you wanted? All you have to do is give newx and newy the same values as x and y...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum