Resizes an image and returns the resized URL. Uses native WordPress functionality.
The function supports GD Library and ImageMagick. WordPress will pick whichever is most appropriate. If none of the supported libraries are available, the function will return the original image url.
Images are saved to the WordPress uploads directory, just like images uploaded through the Media Library.
Supports WordPress 3.5 and above.
Positional Cropping is supported using timthumb-compatible parameters, which allow you to control how the image is cropped.
Based on resize.php by Matthew Ruddy.
The function accepts the following parameters:
$urlimage URL to process$widthoutput width$heightoutput height$cropenables cropping (true by default)$alignpositional cropping parameter (defaults to center)$retinause double pixel ratio (true by default)
If either $width or $height is not specified, its value will be calculated proportionally.
// Put this in your functions.php
function theme_thumb($url, $width, $height=0, $align='') {
return mr_image_resize($url, $width, $height, true, $align, false);
}
$thumb = theme_thumb($image_url, 800, 600, 'br'); // Crops from bottom right
echo $thumb;The $align parameter accepts the following arguments:
cposition in the center (default)talign toptralign top righttlalign top leftbalign bottombralign bottom rightblalign bottom leftlalign leftralign right
If an image has the nocrop query string parameter, processing will be ignored, returning the original URL.
GPLv2, See LICENSE for details.