Code: Select all
// THUMBNAILS
function imagestringcentered($img, $font, $text, $color) {
$cy = (imagesy($img)/2) - (imagefontwidth($font)/2);
imagestring($img,$font,imagesx($img) / 2 - strlen($text) * imagefontwidth($font) / 2,$cy,$text,$color);
}
//$destination = filename of original, not-watermarked large photograph
$imageinfo = array();
$imageinfo = getimagesize($destination,$imageinfo);
$image = imagecreatefromjpeg($destination);
imagejpeg($image, '/home/ap/public_html/thumbnails/' . $insert->insertID() . '.jpg'); //copy original to thumbnails
imagejpeg($image, '/home/ap/public_html/photos/' . $insert->insertID() . '.jpg'); //copy original to photos (smaller version, but not too small)
$old_x = $imageinfo[0];
$old_y = $imageinfo[1];
$new_y = (500/$old_x)*$old_y; //always 500 pixels wide
$old_photo = imagecreatefromjpeg('/home/ap/public_html/photos/' . $insert->insertID() . '.jpg');
imagestringcentered($old_photo, 6, 'Copyright AbovePhotography.com.au', imagecolorallocate($old_photo, 255, 255, 255));
$photo = imagecreatetruecolor(500,$new_y);
$white = imagecolorallocate($photo,255,255,255);
imagefill($photo,0,0,$white);
imagecopyresampled ( $photo, $old_photo, 0, 0, 0, 0, 500, $new_y, $old_x, $old_y);
$new_y = (200/$old_x)*$old_y; //always 200 pixels wide
$old_thumb = imagecreatefromjpeg('/home/ap/public_html/thumbnails/' . $insert->insertID() . '.jpg');
$thumbnail = imagecreatetruecolor(200,$new_y);
$white = imagecolorallocate($thumbnail,255,255,255);
imagefill($thumbnail,0,0,$white);
imagecopyresampled ( $thumbnail, $old_thumb, 0, 0, 0, 0, 200, $new_y, $old_x, $old_y);
imagejpeg($thumbnail, '/home/ap/public_html/thumbnails/' . $insert->insertID() . '.jpg');
imagejpeg($photo, '/home/ap/public_html/photos/' . $insert->insertID() . '.jpg');
imagedestroy($image);
imagedestroy($thumbnail);
imagedestroy($photo);- Nathaniel