Redimensionar una imagen a formato de banner

/**
 * Redimensionar imagen a formato banner predeterminado 200 x 60 
 *
 * @param unknown_type $p_banner_file, $p_width anchura deseada, $p_height altura deseada
 * @return String con los parametros width y height rellenados
 */
function image_banner_size($p_image_file, $p_width = 200, $p_height = 60)
{
	if (!file_exists($p_image_file))
	{
		return "";
	}
	$imagesize = getimagesize("$p_image_file");
	$width_height = " width=\"". $imagesize[0]."\" height=\"". $imagesize[1]."\" ";
	$relation = $p_width / $p_height;
	if ($imagesize[0] > $p_width && $imagesize[1] > $p_height)
	{
		$relation = $imagesize[0]/$imagesize[1];
		if ($relation > 3.33)
		{
			$width_height = " width=\"200\" ";
		}
		else 
		{
			$width_height = " height=\"60\" ";
		}
	}
	elseif ($imagesize[0] > 200)
	{
		$width_height = " width=\"200\" ";
	}
	elseif ($imagesize[1] > 60)
	{
		$width_height = " height=\"60\" ";
	}
	return $width_height;
}

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *