PHP Wordpress功能使用timthumb进行图像大小调整

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Wordpress功能使用timthumb进行图像大小调整相关的知识,希望对你有一定的参考价值。

// http://www.binarymoon.co.uk/2012/02/complete-timthumb-parameters-guide/
function get_thumb_src($src, $width="100", $height="100", $quality="85", $alignment="", $zoomcrop="", $filters="", $sharpen="", $canvascolor="", $transparency=""){
	
	if($src=="") return FALSE;

	$src 			= "src=".$src;
	$width			= "&w=".$width;
	$height			= "&h=".$height;
	$quality		= "&q=".$quality;
	$alignment		= (!empty($alignment)) ? "&a=".$alignment : "";
	$zoomcrop		= (!empty($zoomcrop)) ? "&zc=".$zoomcrop : "";
	$filters		= (!empty($filters)) ? "&f=".$filters : "";
	$sharpen		= (!empty($sharpen)) ? "&s=".$sharpen : "";
	$canvascolor	= (!empty($canvascolor)) ? "&cc=".$canvascolor : "";
	$transparency	= (!empty($transparency)) ? "&ct=".$transparency : "";

	return get_template_directory_uri()."/sized.php?".$src.$width.$height.$quality.$alignment.$zoomcrop.$filters.$sharpen.$canvascolor.$transparency;
}
function the_thumb_src($src, $width="100", $height="100", $quality="85", $alignment="", $zoomcrop="", $filters="", $sharpen="", $canvascolor="", $transparency=""){
	if($thumb = get_thumb_src($src, $width, $height, $quality, $alignment, $zoomcrop, $filters, $sharpen, $canvascolo, $transparency)){
		echo $thumb;
	}
}
function get_thumb($src, $alt="", $classes="", $id=""){
	return "<img class='".$classes."' id='".$id."' src='".$src."' alt='".$alt."' />";
}
function the_thumb($src, $alt="", $classes="", $id=""){
	echo get_thumb($src, $alt, $classes, $id);
}
function get_main_thumb($post_id, $alt="", $classes="", $id="", $width="", $height=""){
	$src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), "full", false);
	if($src[0]=="") return FALSE;
	$width = ($width!="") ? $width : "750";
	$height = ($height!="") ? $height : "250";
    $src = get_thumb_src($src[0], $width, $height);
	return "<img class='".$classes."' id='".$id."' src='".$src."' alt='".$alt."' />";
}
function the_main_thumb($post_id, $alt="", $classes="", $id="", $width="", $height=""){
	if($thumb = get_main_thumb($post_id, $alt, $classes, $id, $width, $height)){
		echo $thumb;
	}
}

以上是关于PHP Wordpress功能使用timthumb进行图像大小调整的主要内容,如果未能解决你的问题,请参考以下文章

PHP Wordpress - 使用TimThumb重新调整图像大小

PHP Wordpress MU timthumb修复

带有 .htaccess 的 timthumb.php 友好 URL

Wordpress-使用TimThumb调整图像大小

Wordpress使用timthumb调整图像大小的函数

Wordpress拇指