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

Posted

tags:

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

This uses the timthumb script saved as sized.php in the theme directory
  1. // http://www.binarymoon.co.uk/2012/02/complete-timthumb-parameters-guide/
  2. function get_thumb_src($src, $width="100", $height="100", $quality="85", $alignment="", $zoomcrop="", $filters="", $sharpen="", $canvascolor="", $transparency=""){
  3.  
  4. if($src=="") return FALSE;
  5.  
  6. $src = "src=".$src;
  7. $width = "&w=".$width;
  8. $height = "&h=".$height;
  9. $quality = "&q=".$quality;
  10. $alignment = (!empty($alignment)) ? "&a=".$alignment : "";
  11. $zoomcrop = (!empty($zoomcrop)) ? "&zc=".$zoomcrop : "";
  12. $filters = (!empty($filters)) ? "&f=".$filters : "";
  13. $sharpen = (!empty($sharpen)) ? "&s=".$sharpen : "";
  14. $canvascolor = (!empty($canvascolor)) ? "&cc=".$canvascolor : "";
  15. $transparency = (!empty($transparency)) ? "&ct=".$transparency : "";
  16.  
  17. return get_template_directory_uri()."/sized.php?".$src.$width.$height.$quality.$alignment.$zoomcrop.$filters.$sharpen.$canvascolor.$transparency;
  18. }
  19. function the_thumb_src($src, $width="100", $height="100", $quality="85", $alignment="", $zoomcrop="", $filters="", $sharpen="", $canvascolor="", $transparency=""){
  20. if($thumb = get_thumb_src($src, $width, $height, $quality, $alignment, $zoomcrop, $filters, $sharpen, $canvascolo, $transparency)){
  21. echo $thumb;
  22. }
  23. }
  24. function get_thumb($src, $alt="", $classes="", $id=""){
  25. return "<img class='".$classes."' id='".$id."' src='".$src."' alt='".$alt."' />";
  26. }
  27. function the_thumb($src, $alt="", $classes="", $id=""){
  28. echo get_thumb($src, $alt, $classes, $id);
  29. }
  30. function get_main_thumb($post_id, $alt="", $classes="", $id="", $width="", $height=""){
  31. $src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), "full", false);
  32. if($src[0]=="") return FALSE;
  33. $width = ($width!="") ? $width : "750";
  34. $height = ($height!="") ? $height : "250";
  35. $src = get_thumb_src($src[0], $width, $height);
  36. return "<img class='".$classes."' id='".$id."' src='".$src."' alt='".$alt."' />";
  37. }
  38. function the_main_thumb($post_id, $alt="", $classes="", $id="", $width="", $height=""){
  39. if($thumb = get_main_thumb($post_id, $alt, $classes, $id, $width, $height)){
  40. echo $thumb;
  41. }
  42. }

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

Wordpress-使用TimThumb调整图像大小

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

带有 .htaccess 的 timthumb.php 友好 URL

自动调整图像大小

如何重写用于电子邮件的 TimThumb

如何在不使用css调整第一个图像大小的情况下在Wordpress页面上调整第二个图像的大小?