NameSilo

Php gallery

SpaceshipSpaceship
Watch

skrilla

VIP Member
Impact
11
Im making a php gallery for a site im workin on www.paruch.com/modeling
my auto thumber resizes the pics right now to height 120 by width 160, but i would like to make the height Proportioned to the width.. can anyone help me out here? this is how i am currently doing it

/////////////////////////////////////////////////////////////////////
// Get image specs //
/////////////////////////////////////////////////////////////////////

$size = GetImageSize($picture);
$oldwidth = $size[0];
$oldheight = $size[1];

/////////////////////////////////////////////////////////////////////
// Create the large thumbnail //
/////////////////////////////////////////////////////////////////////
// Set the image specs you want! //
/////////////////////////////////////////////////////////////////////

$newheight = 120;
$newwidth = 160;

$newthumb = imagecreatetruecolor($newwidth, $newheight);


imagecopyresized($newthumb, $oldimg, 0 , 0 , 0 , 0 , ($newwidth), ($newheight), $oldwidth, $oldheight);
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Just change the numbers in the code.


$newheight = 120;
$newwidth = 160;

To:

$newheight = 160;
$newwidth = 160;

Or:

$newheight = 120;
$newwidth = 120;
 
0
•••
no, thats not what i mean....... My pictures dont look right after they are thumbed, they look all scrunched up..... you know how in photoshop you can have constraints on.. thats basicly what i want to do.. if the height is set to be 120, i want the width to be constrained..
 
0
•••
I think you'll have to calculate the ratio aspect, then calculate the two possible value, width with ratio, or height with ratio, and you'll take the best fit.
 
0
•••
does anybody have pre written code to do this? I'v been racking my brain on this all night, and i dont think i can stand to sit down and calculate anythign..lol..
 
0
•••
lol

Maybe I've a code snippet about that, I'll look for that tomorrow...
 
0
•••
kool thnx man...
 
0
•••
Here is what I use, your milage may vary,

The important part for you are the following two lines,

$imgsize = getImageSize($_FILES['photo']['tmp_name'][$i]);
$thumb_y = round(($imgsize[1] * $PICTURE_THUMB_X) / $imgsize[0]);

This creates an image that is only x pixels wide and scales the height so the picture does not look distorted.

Code:
function postImages($ad_id, $quality=70)
{
    global $MAX_PICTURE_SIZE, $PICTURE_THUMB_Y, $PICTURE_THUMB_X;
    if ((int)$ad_id)
    {
        for( $i = 0; $i < count($_FILES['photo']); $i++ )
        {
            if ($_FILES['photo']['name'][$i] != '' && $_FILES['photo']['name'][$i] != 'none')
            {
                if ($_FILES['photo']['size'][$i] > $MAX_PICTURE_SIZE) error('Invalid image size');
                if ($_FILES['photo']['type'][$i] == 'image/pjpeg' || $_FILES['photo']['type'][$i] == 'image/jpeg')
                {
                    mysql_query('INSERT INTO photo (ad_id) VALUES (' . $ad_id .')') or error(mysql_error());
                    $photoid = mysql_insert_id();

                    $imgsize = getImageSize($_FILES['photo']['tmp_name'][$i]);
                    $thumb_y = round(($imgsize[1] * $PICTURE_THUMB_X) / $imgsize[0]);
                    makeThumb($_FILES['photo']['tmp_name'][$i], IMAGE_DIR . '/thumb/' . $photoid . '.jpg', $PICTURE_THUMB_X, $thumb_y,90);

                    if ($imgsize[0] > 640)
                    {
                        makethumb($_FILES['photo']['tmp_name'][$i], IMAGE_DIR . "/{$photoid}.jpg", 640, 480);
                    }
                    else
                    {
                        copy($_FILES['photo']['tmp_name'][$i], IMAGE_DIR . '/' . $photoid . '.jpg');
                        //copy ($photo[$i]['tmp_name'], IMAGE_DIR . "/{$photoid}.jpg" );
                    }
                }
                else
                {
                    error('Invalid image type, JPEG only');
                }
            }
        }
    }
}

    function makeThumb($scrFile, $dstFile, $dstX=120, $dstY=100, $quality=75)
    {
        $im = ImageCreateFromJPEG($scrFile);
        $srcW = ImageSX($im);
        $srcH = ImageSY($im);
        $ni = ImageCreateTrueColor($dstX, $dstY);
        ImageCopyResized( $ni, $im, 0, 0, 0, 0, $dstX, $dstY, $srcW, $srcH );
        ImageJPEG($ni, $dstFile, $quality);
    }
 
Last edited:
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy — Live Options
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back