library/Helper/Image.php
public static function resize($originalImage, $width, $height, $crop = true)
    {
        $imagePath = false;

        // Image from attachment id
        if (is_numeric($originalImage)) {
            $imagePath = wp_get_attachment_url($originalImage);
        } elseif (in_array(substr($originalImage, 0, 7), array('https:/', 'http://'))) {
            $imagePath = self::urlToPath($originalImage);
        }

        if (!$imagePath) {
            return false;
        }

        $imagePath = self::removeImageSize($imagePath);

        if (!file_exists($imagePath)) {
            return false;
        }

        $imagePathInfo = pathinfo($imagePath);

        $ext       = $imagePathInfo['extension'];
        $suffix    = "{$width}x{$height}";
        $destPath = "{$imagePathInfo['dirname']}/{$imagePathInfo['filename']}-{$suffix}.{$ext}";

        if (file_exists($destPath)) {
            return self::pathToUrl($destPath);
        }

        if (image_make_intermediate_size($imagePath, $width, $height, $crop)) {
            return self::pathToUrl($destPath);
        }

        return $originalImage;
    }
public static function resize($originalImage, $width, $height, $crop = true)
    {
        $imagePath = false;

        // Image from attachment id
        if (is_numeric($originalImage)) {
            $imagePath = wp_get_attachment_url($originalImage);
        } elseif (in_array(substr($originalImage, 0, 7), array('https:/', 'http://'))) {
            $imagePath = self::urlToPath($originalImage);
        }

        if (!$imagePath) {
            return false;
        }

        $imagePath = self::removeImageSize($imagePath);

        if (!file_exists($imagePath)) {
            return false;
        }

        $imagePathInfo = pathinfo($imagePath);

        $ext       = $imagePathInfo['extension'];
        $suffix    = "{$width}x{$height}";
        $destPath = "{$imagePathInfo['dirname']}/{$imagePathInfo['filename']}-{$suffix}.{$ext}";

        if (file_exists($destPath)) {
            return self::pathToUrl($destPath);
        }

        if (image_make_intermediate_size($imagePath, $width, $height, $crop)) {
            return self::pathToUrl($destPath);
        }

        return $originalImage;
    }
public static function resize ( $ originalImage , $ width , $ height , $ crop = true ) { $ imagePath = false ; // Image from attachment id if ( is_numeric ( $ originalImage ) ) { $ imagePath = wp_get_attachment_url ( $ originalImage ) ; } elseif ( in_array ( substr ( $ originalImage , 0 , 7 ) , array ( 'https:/' , 'http://' ) ) ) { $ imagePath = self :: urlToPath ( $ originalImage ) ; } if ( ! $ imagePath ) { return false ; } $ imagePath = self :: removeImageSize ( $ imagePath ) ; if ( ! file_exists ( $ imagePath ) ) { return false ; } $ imagePathInfo = pathinfo ( $ imagePath ) ; $ ext = $ imagePathInfo [ 'extension' ] ; $ suffix = "{$width}x{$height}" ; $ destPath = "{$imagePathInfo['dirname']}/{$imagePathInfo['filename']}-{$suffix}.{$ext}" ; if ( file_exists ( $ destPath ) ) { return self :: pathToUrl ( $ destPath ) ; } if ( image_make_intermediate_size ( $ imagePath , $ width , $ height , $ crop ) ) { return self :: pathToUrl ( $ destPath ) ; } return $ originalImage ; }
Resizes an image to a specified size
@param  integer|string  $originalImage Attachment id, path or url
@param  integer         $width         Target width
@param  integer         $height        Target height
@param  boolean         $crop          Crop or not?
@return string                         Image url
Resizes an image to a specified size