/ Published in: PHP
Expand |
Embed | Plain Text
function set_thumb($file, $photos_dir=�uploads/photos�,$thumbs_dir=�uploads/photos/thumbs�, $square_size=167, $quality=100) { //check if thumb exists //get image info //set dimensions if($width> $height) { $width_t=$square_size; //respect the ratio //set the offset $off_x=0; } elseif($height> $width) { $height_t=$square_size; $off_y=0; } else { $width_t=$height_t=$square_size; $off_x=$off_y=0; } $thumb=imagecreatefromjpeg($photos_dir."/".$file); $thumb_p = imagecreatetruecolor($square_size, $square_size); //default background is black $bg = imagecolorallocate ( $thumb_p, 255, 255, 255 ); imagefill ( $thumb_p, 0, 0, $bg ); imagecopyresampled($thumb_p, $thumb, $off_x, $off_y, 0, 0, $width_t, $height_t, $width, $height); imagejpeg($thumb_p,$thumbs_dir."/".$file,$quality); } }
You need to login to post a comment.
