Skip to content

alettieri/wp-image-resize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

WP-Image-Resize

A helper function that resizes images using WordPress' built in wp_get_image_editor function.

Function:

get_image_thumb( $src, $opts );

Parameters:

  • $src - Image src (url or path)
  • $opts (optional) - Resize options

$opts:

array (
    "w" => 500,
    "h" => 200,
    "q" => 100, // Quality
    "crop" => false // Crop image
);

$opts - Default Values:

array(
    "w" => PHP_INT_MAX, // Won't resize if image width is smaller than default width
    "h" => PHP_INT_MAX, // Won't resize if image height is smaller than default height
    "q" => 95,
    "crop" => false
);

Example:

$id = get_post_thumbnail_id( get_the_ID() );
$src = wp_get_attachment_image_src( $id, $size );
$src = $src[0];

$newImage = get_image_thumb( $src, array( "w" => 50, "h" => 50, "q" => 75, "crop" => true ) );

OR:

$newImage = get_image_thumb( $src, "w=50&h=50&q=75&crop=true" );

About

WordPress Image Resize Function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages