Skip to content

mendezcode/mr-image-resize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

mr-image-resize

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.

Parameters

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.

Example Usage

// 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;

Positional Cropping

The $align parameter accepts the following arguments:

  • c position in the center (default)
  • t align top
  • tr align top right
  • tl align top left
  • b align bottom
  • br align bottom right
  • bl align bottom left
  • l align left
  • r align right

Skip Processing

If an image has the nocrop query string parameter, processing will be ignored, returning the original URL.

License

GPLv2, See LICENSE for details.

About

Native WordPress Image Processing Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages