0

I'm trying to programmatically increase the size of images that are uploaded. I want to double the size of each image. The code I've written so far is:

$pathDirectory = dirname( $imagePath );
$large_w = $width*2; // These values are correct
$large_h = $height*2; // These values are correct
$largeImage = wp_get_image_editor( $imagePath );
$largeFilename = $largeImage->generate_filename("large", $pathDirectory, $ext);
$largeImage->set_quality(100);  
$largeImage->resize($large_w, $large_h, false);
$largeImage->save($largeFilename);

This is making an image with the '-large' bit in the filename but it's exactly the same size as the original image. After reading the WP manual is says regarding resize:

resize( $max_w, $max_h, $crop = false ) // NOTE - max width and max height
Resizes current image.

So I'm thinking that resize only makes images smaller?

Am I right in assuming this and, if so, how do I make images bigger with WP?

Thanks for your help :-)

  • 1
    If you want retina images, you should be uploading at twice the required size, and then creating a non-retina version at 50%. Upscaling an image for retina is pointless, it'll look just as blurry, if not more so, than leaving the retina device to upscale itself. – TheDeadMedic Jun 7 '14 at 14:02
  • That is a very very very good point! Doh! I shall create my retina version first and then downsize for the other images. Would still like to know how to increase the size of the image though. Will update my question... :-) – John T Jun 7 '14 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.