Wordpress functions for image resizing using timthumb


/ Published in: PHP
Save to your folder(s)

This uses the timthumb script saved as sized.php in the theme directory


Copy this code and paste it in your HTML
  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. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.