Last active
August 29, 2015 14:07
-
-
Save rickalday/3accbe8f788b8273fd8b to your computer and use it in GitHub Desktop.
WordPress image resize functon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Resize an image to the specified dimensions | |
* http://codex.wordpress.org/Class_Reference/WP_Image_Editor | |
* | |
* Returns the new image file path | |
* | |
* @param image_url | |
* @param width | |
* @param width | |
* @return resized image file path | |
function image_resize( $image_url=null, $width=null, $height=null ){ | |
$img = wp_get_image_editor( $image_url ); | |
if ( ! is_wp_error( $img ) ) { | |
// resize if height and width supplied | |
if ( $width || $height ) { | |
if ( $width >= $height ) { | |
$max = $width; | |
} else { | |
$max = $height; | |
} | |
$img->resize( $max, $max, false ); | |
$img->set_quality( 100 ); | |
} | |
$img->stream(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment