resize() public static method

New dimensions are achieved by cropping to maintain ratio.
public static resize ( string $src, integer | string $w, integer $h, string $crop = 'default', boolean $force = false ) : string
$src string an URL (absolute or relative) to the original image
$w integer | string target width(int) or WordPress image size (WP-set or user-defined).
$h integer target height (ignored if $w is WP image size). If not set, will ignore and resize based on $w only.
$crop string your choices are 'default', 'center', 'top', 'bottom', 'left', 'right'
$force boolean
return string (ex: )
Ejemplo n.º 1
0
 /**
  * Resize an image and apply letterbox and tojpg filters when defined.
  *
  * @since 0.9.2
  *
  * @param  array    $img_size 	Configuration values for an image size
  * @param  string   $file_src   The src of the original image
  * @param  int      $width    	The width the new image should be resized to
  * @param  int      $height   	The height the new image should be resized to
  * @param  string   $crop       Cropping option
  * @param  bool     $force    	Force cropping
  * @return string               The src of the image
  */
 public static function resize($img_size, $file_src, $width, $height, $crop, $force)
 {
     // Check if image should be converted to jpg first
     if (isset($img_size['tojpg']) && $img_size['tojpg']) {
         // Sort out background color which will show instead of transparency
         $bgcolor = is_string($img_size['tojpg']) ? $img_size['tojpg'] : '#FFFFFF';
         $file_src = Timber\ImageHelper::img_to_jpg($file_src, $bgcolor, $force);
     }
     // Check for letterbox parameter
     if (isset($img_size['letterbox']) && $img_size['letterbox'] && $width > 0 && $height > 0) {
         $color = is_string($img_size['letterbox']) ? $img_size['letterbox'] : '#000000';
         return Timber\ImageHelper::letterbox($file_src, $width, $height, $color);
     } else {
         return Timber\ImageHelper::resize($file_src, $width, $height, $crop, $force);
     }
 }