Code: Select all
<?php
function savepic ($max_width, $max_height, $file, $filename){
/*image resizing code
*returns: jpeg image that is destroyed as soon as it's outputted
*paramaeters that must be passed: $max_width, $max_hieght, $file
*$max_width/$max_height are the maximum size of the picture in pizels
*if not set, they default to 100 */
if (@!$max_width)
$max_width = 100;
if (@!$max_height)
$max_height = 100;
//$root_dir = "C:/apache2triad/htdocs/tmeet/";
$root_dir = "/home/vlad/public_html/";
$directory = $root_dir . "pics"; //direcotry where $file is stored
$size = GetImageSize($file);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
//watermark
$watermark = imagecreatefrompng('images/tmeet_watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$watermarkimage = imagecreatetruecolor($watermark_width, $watermark_height);
$dest_x = $tn_width - $watermark_width - 5;
$dest_y = $tn_height - $watermark_height - 5;
//end watermark
$src = ImageCreateFromJpeg($file);
$dst = ImageCreateTrueColor($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
//merge with watermark
imagecopymerge($dst, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
ImageJpeg ($dst, $root_dir . $filename, 90);
ImageDestroy($src);
ImageDestroy($dst);
imagedestroy($watermark);
//end image resizing code
}