I wanted to know, if there is any function to handle following case: I have registered image size of 200x200, Now if user uploads 100x100 or 800x120 the thumbnail of 200x200 will not be generated. I want to generate 200x200 by adding padding to thumbnail.

1 Answer 1


There are no built in functions to size-up an image. You might be able to accomplish what you are looking for by using wp_get_attachment_metadata and an Image processor like GD or Imagegick if your host supports it. Normally at least one of them is supported.

So wp_get_attachment_metadata returns an array on success or bool false on failure. So given (pseudocode):

$thumbnail = wp_get_attachment_metadata( $attachment_id );

if( $thumbnail['width'] < 100 || $thumbnail['height'] < 100 ){

  do_image_padding( $thumbnail, $width = 200, $height = 200 );


Now of course do_image_padding doesn't exist in WP, but it's possible with GD library to create this function that would take in as parameters, the thumbnail, the width and the height and render the new image with padding.

This extensive explanation using GD by bumberbox over at stackoverflow should put you on the right track to built that do_image_padding function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.