$width || $image_src[2] > $height ) { // the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match) if ( file_exists( $cropped_img_path ) ) { $cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] ); $vt_image = array( 'url' => $cropped_img_url, 'width' => $width, 'height' => $height ); return $vt_image; } if ( $crop == false ) { // calculate the size proportionaly $proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height ); $resized_img_path = $no_ext_path . '-' . $proportional_size[0] . 'x' . $proportional_size[1] . $extension; // checking if the file already exists if ( file_exists( $resized_img_path ) ) { $resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] ); $vt_image = array( 'url' => $resized_img_url, 'width' => $proportional_size[0], 'height' => $proportional_size[1] ); return $vt_image; } } // no cache files - let's finally resize it $img_editor = wp_get_image_editor( $actual_file_path ); if ( is_wp_error( $img_editor ) || is_wp_error( $img_editor->resize( $width, $height, $crop ) ) ) { return array('url' => '', 'width' => '', 'height' => ''); } $new_img_path = $img_editor->generate_filename(); if ( is_wp_error( $img_editor->save( $new_img_path ) ) ) { return array('url' => '', 'width' => '', 'height' => ''); } if ( ! is_string( $new_img_path ) ) { return array('url' => '', 'width' => '', 'height' => ''); } $new_img_size = getimagesize( $new_img_path ); $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] ); // resized output $vt_image = array( 'url' => $new_img, 'width' => $new_img_size[0], 'height' => $new_img_size[1] ); return $vt_image; } $vt_image = array('url' => $image_src[0],'width' => $image_src[1],'height' => $image_src[2]); return $vt_image; } else { if ( $place_hold ) { $width = intval( $width ); $height = intval( $height ); $color = str_pad( dechex( mt_rand( 1, 255 ) ), 2, '0', STR_PAD_LEFT ) . str_pad( dechex( mt_rand( 1, 255 ) ), 2, '0', STR_PAD_LEFT ) . str_pad( dechex( mt_rand( 1, 255 ) ), 2, '0', STR_PAD_LEFT ); $vt_image = array( 'url' => 'http://placehold.it/' . $width . 'x' . $height . '/' . $color . '/ffffff/', 'width' => $width, 'height' => $height ); return $vt_image; } } return false; }