Advertisement
azad_rpi

Kc Image size

Sep 11th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. // image field
  2. array(
  3.     'type'          => 'text',
  4.     'label'         => __( 'Image Size', 'wphash' ),
  5.     'name'          => 'img_size',
  6.     'value'         => 'thumbnail ',
  7.     'description'   => __(' Set the image size: "full", "thumbnail", "medium", "large" or other size. ex: 250x200', 'wphash'),
  8.  
  9. ),
  10.  
  11.  
  12. // image data output
  13. $data_image = '';
  14. $size_array = array('full', 'medium', 'large', 'thumbnail');
  15.  
  16. if ($image) {
  17.     $image_full_width_data  = wp_get_attachment_image_src( $image, 'full' );
  18.     $image_full             = $image_full_width_data[0];
  19.     $image_alt              = get_post_meta( $image, '_wp_attachment_image_alt', true);
  20.    
  21.     if( in_array( $img_size, $size_array ) ){
  22.         $image_data       = wp_get_attachment_image_src( $image, $img_size );
  23.         $image_url        = $image_data[0];
  24.     }else{
  25.         $image_url  = kc_tools::createImageSize( $image_full, $img_size );
  26.     }
  27.  
  28.     $data_image .= '<div class="activity-icon">';
  29.         $data_image .= '<img src="'.$image_url.'" alt="'.$image_alt.'" >';
  30.     $data_image .= '</div>';
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement