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:
$url
image URL to process$width
output width$height
output height$crop
enables cropping (true by default)$align
positional cropping parameter (defaults to center)$retina
use 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:
c
position in the center (default)t
align toptr
align top righttl
align top leftb
align bottombr
align bottom rightbl
align bottom leftl
align leftr
align right
If an image has the nocrop
query string parameter, processing will be ignored, returning the original URL.
GPLv2, See LICENSE for details.