image question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jrucifer
Forum Commoner
Posts: 32
Joined: Fri May 13, 2005 2:36 pm
Location: phoenix

image question

Post by jrucifer »

okay, so i'm making thumbnails for a portfolio website, and everything is working perfectly but i have just one question. I am making the thumbnails just a resized portion of the image. The only problem is since the demensions of the image are measured from the top left corner, the thumbnail is always the top portion of the image, so it looks a little weird in repitition. my question is, is there any way to start the image demensions from a random spot, or anywhere besides the top left corner. any help is appreciated. here is the code i am currently using:

Code: Select all

//Thumbnail size
$dest_x = 178; 
$dest_y = 55; 
//Image reduction
$iratio = 3.23;
$widthratio = $width_orig / $iratio;
$heightratio = $height_orig / $iratio;
    if ($width_orig >= $height_orig) { 
        $width_new = $width_orig;
        $height_new = $heightratio;
    } else { 
         $width_new = $width_orig;
        $height_new = $widthratio;
    }
//Generate a new image at the size of the thumbnail 
$thumb = imagecreatetruecolor($dest_x,$dest_y); 
//Copy the original image data to it using resampling 
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $dest_x, $dest_y, $width_new, $height_new); 
//Save the thumbnail 
imagejpeg($thumb, "images/work/$type/thumb_$filename", 80); 
		}
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

If your image is X pixels wide and you will be cutting off Y pixels, add 1/2 Y to the offset, if you want it random juse use a random number instead of 0
Post Reply