2

I want to create large images though my original image is smaller.

I have original images 1024x768 in my media library, and i want to resize these images to 1920x1080px in my WordPress posts.

I used add_image_size( 'large', 1920, 1080, true );

but it is not working, please tell me what to do to get large image sizes

2
  • Even if you are able to enlarge the image, I am sure there will be significant loss in quality of the image. That is why generally images are resized down, not resized up. Also this is not a wordpress specific question.
    – gurung
    Commented Aug 22, 2015 at 19:27
  • @gurung: it is a very wordpress specific question and your answer is about quality which is irrelevant as it doesn't address the how. I too would like to know how to technically force wordpress to resize to a specific size even if the original picture is smaller than the target size.
    – Baylock
    Commented Dec 10, 2015 at 4:59

1 Answer 1

3

Found a solution here that is working:

http://www.binarynote.com/how-to-perfectly-upscale-image-in-wordpress.html

function binary_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop )
{
    if ( !$crop ) return null; 
    $aspect_ratio = $orig_w / $orig_h;
    $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
    $crop_w = round($new_w / $size_ratio);
    $crop_h = round($new_h / $size_ratio);
    $s_x = floor( ($orig_w - $crop_w) / 2 );
    $s_y = floor( ($orig_h - $crop_h) / 2 );
    return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
add_filter( 'image_resize_dimensions', 'binary_thumbnail_upscale', 10, 6 );

As gurung says, it is not ideal and Wordpress doesn't upscale for a reason but if you know what you do and use Wordpress more as a framework to suit your specific needs, this will get the job done. In my case, it solves some grid layout issues.

I hope it helps.

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.