Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Last active December 17, 2015 05:03
Show Gist options
  • Select an option

  • Save vishalbasnet23/f6d95d93bcf42b7141c7 to your computer and use it in GitHub Desktop.

Select an option

Save vishalbasnet23/f6d95d93bcf42b7141c7 to your computer and use it in GitHub Desktop.
Thumb Resizer with BFI_thumb WordPress
Usage:
Download BFI_thumb.php file from https://github.com/bfintal/bfi_thumb and copy it into your 'inc' folder of your theme.
<img src="<?php echo code_project_img( $thumb_size, $image_width, $image_height );?> />
<?php
require get_template_directory() . '/inc/BFI_Thumb.php';
/**
* [code_project_img bfi thumb src inside loop]
* @param [string] $thumb_size [wp thumb size]
* @param [int] $image_width [width to crop]
* @param [int] $image_height [height to crop]
* @return [string] $custom_img_src [src of cropped image]
*/
function code_project_img( $thumb_size, $image_width, $image_height ) {
global $post;
$params = array( 'width' => $image_width, 'height' => $image_height );
$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID, '' ), $thumb_size );
$custom_img_src = bfi_thumb( $imgsrc[0], $params );
return $custom_img_src;
}
/**
* [code_project_img_by_id bfi thumb src outside loop]
* @param [int] $post_id [post id of the post]
* @param [string] $thumb_size [wp thumb size]
* @param [int] $image_width [width to crop]
* @param [int] $image_height [height to crop]
* @return [string] $custom_img_src [src of cropped image]
*/
function code_project_img_by_id( $post_id, $thumb_size, $image_width, $image_height ) {
$params = array( 'width' => $image_width, 'height' => $image_height );
$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id, '' ), $thumb_size );
$custom_img_src = bfi_thumb( $imgsrc[0], $params );
return $custom_img_src;
}
/**
* [code_no_image_thumb_placeholder post archive thumb of no image placeholder]
* @return [string] [cropped image tag of no image place holder]
*/
function code_no_image_thumb_placeholder( $thumb_width = '560', $thumb_height = '320' ) {
$params = array( 'width' => $thumb_width, 'height' => $thumb_height );
$bfi_image_size = bfi_thumb( get_template_directory_uri().'/img/no-img-available.jpg', $params );
return '<img src="'.$bfi_image_size.'" alt="no-image"/>';
}
/**
* [code_no_image_full_placeholder full width thumb of no image placeholder]
* @return [string] [cropped image tag of no image place holder]
*/
function code_no_image_full_placeholder( $full_width = '1170', $full_height = '420' ) {
$params = array( 'width' => 1170, 'height' => 420 );
$bfi_image_size = bfi_thumb( get_template_directory_uri().'/img/single-no-img-available.jpg', $params );
return '<img src="'.$bfi_image_size.'" alt="no-image" class="featured-image"/>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment