Current File : /home/inlingua/www/sensoriumpsychologists.com/include/function/image_manipulation.php
<?
function link_image($name)
{
	return '<img src="'.DIR_WS_SITE_GRAPHIC.$name.'" border="0">';
}

function create_thumb($type, $image){
    
	// Get the original geometry and calculate scales
	echo $source_path=DIR_FS_SITE.'upload/photo/'.$type.'/large/'.$image;
	echo $destination_path=DIR_FS_SITE.'upload/photo/'.$type.'/thumb/'.$image;
	list($width, $height) = getimagesize($source_path);
    $xscale=$width/THUMB_WIDTH;
    $yscale=$height/THUMB_HEIGHT;
    
    // Recalculate new size with default ratio
    if ($yscale>$xscale){
        $new_width = round($width * (1/$yscale));
        $new_height = round($height * (1/$yscale));
    }
    else {
        $new_width = round($width * (1/$xscale));
        $new_height = round($height * (1/$xscale));
    }

    // Resize the original image & output
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    $imageTmp     = imagecreatefromjpeg ($source_path);
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    output_img($imageResized, image_type_to_mime_type(getimagesize($source_path)), $destination_path);
}

function output_img($rs, $mime, $path)
{
	switch ($mime)
	{
		case 'image/jpeg':
		case 'image/jpg':
		case 'image/pjpeg':
		case 'image/pjpg':
				imagejpeg($rs, $path, 8);
				break;
		case 'image/gif':
				imagegif($rs, $path, 8);
				break;
		case 'image/png':
				imagepng($rs, $path, 8);
				break;
		default:
				imagejpeg($rs, $path, 8);
	}
}

function get_thumb($type, $image)
{
	echo DIR_WS_SITE.'upload/photo/'.$type.'/thumb/'.$image;
}

function delete_if_image_exists($type, $size, $image)
{
	if(file_exists(DIR_FS_SITE.'upload/photo/'.$type.'/'.$size.'/'.$image)):
		unlink(DIR_FS_SITE.'upload/photo/'.$type.'/'.$size.'/'.$image);
	endif;
}

function upload_photo($type, $file_name)
{
	global $conf_allowed_photo_mime_type;
	if($file_name['error']):
		return false;
	endif;
	if(in_array($file_name['type'], $conf_allowed_photo_mime_type)):
		delete_if_image_exists($type, 'large', $file_name['name']);
		delete_if_image_exists($type, 'thumb', $file_name['name']);
		if(move_uploaded_file($file_name['tmp_name'], DIR_FS_SITE.'upload/photo/'.$type.'/large/'.$file_name['name'])):

			create_thumb($type, $file_name['name']);
			return true;
		else:
			return false;
		endif;
	endif;
	return false;
}

function get_banner($id)
{
	$query= new query('gimage');
	$query->Where="where id='$id'";
	$banner=$query->DisplayOne();
	return $banner->image;
}

function get_large($type, $image)
{
	echo DIR_WS_SITE.'upload/photo/'.$type.'/large/'.$image;
}

function get_control_icon($name)
{
	return '<img src="'.DIR_WS_SITE.ADMIN_FOLDER.'/image/'.$name.'.png" border="none" align="absmiddle">';
}

?>