#61916 closed defect (bug) (invalid)
Improving Image Upload Handling: Automatic Resizing for Large Images
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-testing-info |
Focuses: | Cc: |
Description
When uploading large images (e.g., those with dimensions exceeding 7500 pixels), the system doesn't automatically crop them to the custom size of 2400 pixels using the following code:
<?php add_image_size('custom_size_2400', 2400);
Additionally, there are no restrictions on uploading images of any resolution. Currently, to achieve the desired size, you must manually crop the image to a smaller size before it will resize correctly.
To address this, there should be a setting that automatically converts the uploaded image to the maximum allowed size, after which it will resize according to the specified dimensions.
Change History (11)
#2
@
5 months ago
Hi @hellofromtonya,
Thank you for looking into this issue during the 6.6.x triage. I appreciate your help.
To clarify the problem, when uploading large images (e.g., with dimensions over 7500 pixels), they are not being automatically resized to the custom size I’ve specified using add_image_size('custom_size_2400', 2400);
. It appears that WordPress isn't automatically cropping or resizing these large images down to the maximum allowed size.
Ideally, I would like the system to automatically resize any uploaded image to a maximum of 2400 pixels on the longest side. This way, we can avoid the need for manual cropping or resizing of images before uploading. Could this be related to changes in how WordPress handles image uploads, or is there another setting I should be aware of to enforce this automatic resizing?
Please let me know if there's any more information you need from me, or if there's a workaround or setting I can adjust in the meantime.
Thank you!
#3
@
5 months ago
Reproduction Report
This report validates that the issue can be reproduced.
Environment
- OS: macOS
- Web Server: Nginx
- PHP: 8.3.8
- WordPress: 6.6.2
- Browser: Firefox 15.4
- Theme: Twenty Twenty-Four
- Active Plugins: None
Set up
Image:
I downloaded and used this image which has a size of 8294 × 12440.
For adding the custom size, I added the following file: wp-content/mu-plugins/test.php
with this code:
<?php add_action( 'after_setup_theme', function() { add_image_size( 'custom_size_2400', 2400 ); } );
Test Instructions
- Log into admin.
- Go to Media > Add New Media File.
- Select (or drag and drop) the large image to be uploaded.
- Once uploaded, check the generated scaled images in the
wp-content/uploads/
directory.
🐞 Reported bug occurs here in that there should not be any scaled images with a custom dimension of 2400.
Actual Results
❌ Not able to reproduce the bug.
This image was generated photo-1644433329707-2b528437a7e7-2400x3600.jpg
.
The 8294 × 12440 image was scaled to 2400 x 3600.
#4
@
5 months ago
Reproduction Report
Repeating comment:3 test report but this time specifying both the width and height.
This report validates that the issue can be reproduced.
Environment
- OS: macOS
- Web Server: Nginx
- PHP: 8.3.8
- WordPress: 6.6.2
- Browser: Firefox 15.4
- Theme: Twenty Twenty-Four
- Active Plugins: None
Set up
Image: Same as comment:3
Code: Same as comment:3, except also specified the height.
<?php add_action( 'after_setup_theme', function() { add_image_size( 'custom_size_2400', 2400, 2400 ); } );
Test Instructions
- Log into admin.
- Go to Media > Add New Media File.
- Select (or drag and drop) the large image to be uploaded.
- Once uploaded, check the generated scaled images in the
wp-content/uploads/
directory.
🐞 Reported bug occurs here in that there should not be any scaled images with a custom dimension of 2400.
Actual Results
❌ Not able to reproduce the bug.
This image was generated photo-1644433329707-2b528437a7e7-1600x2400.jpg
.
The 8294 × 12440 image was scaled to 1600 x 2400.
#5
@
5 months ago
Reproduction Report
Repeating comment:3 and comment:4 tests report but this time specifying both the width and height and setting crop to true
.
This report validates that the issue can be reproduced.
Environment
- OS: macOS
- Web Server: Nginx
- PHP: 8.3.8
- WordPress: 6.6.2
- Browser: Firefox 15.4
- Theme: Twenty Twenty-Four
- Active Plugins: None
Set up
Image: Same as comment:3
Code: Same as comment:4, except also specifying to crop the image.
<?php add_action( 'after_setup_theme', function() { add_image_size( 'custom_size_2400', 2400, 2400, true ); } );
Test Instructions
- Log into admin.
- Go to Media > Add New Media File.
- Select (or drag and drop) the large image to be uploaded.
- Once uploaded, check the generated scaled images in the
wp-content/uploads/
directory.
🐞 Reported bug occurs here in that there should not be any scaled images with a custom dimension of 2400.
Actual Results
❌ Not able to reproduce the bug.
This image was generated photo-1644433329707-2b528437a7e7-2400x2400.jpg
.
The 8294 × 12440 image was scaled and cropped to 2400 x 2400.
#6
@
5 months ago
- Keywords has-testing-info reporter-feedback added
@maheshmthorat, I ran 3 different tests by specifying in add_image_size()
:
- comment:3 only the width dimension.
- comment:4 width and height dimensions.
- comment:5 width, height, and to crop the image.
Reference: https://developer.wordpress.org/reference/functions/add_image_size/
Each of the tests worked as expected.
The last test generated a scaled and cropped the image of 2400 x 2400 ✅
So to scale and crop to 2400 x 2400, do this:
add_image_size( 'custom_size_2400', 2400, 2400, true );
Can you check please if changing add_image_size()
works for you? Also, do my tests align to how you are testing the issue you're experiencing?
#7
@
5 months ago
Hi @hellofromTonya,
Thank you for following up on this matter. We have reviewed it, but we are still experiencing issues.
This is our system details https://drive.google.com/file/d/1ePcjuiuUqxhtjVyUu7mmu0EE1bKB0oGo/view?usp=drive_link
When we have uploaded your image we only get single version of image. Please find screen shot here
While uploading the image below, we discovered that multiple versions were created.
With below code
<?php add_action( 'after_setup_theme', function() { add_image_size( 'custom_size_2400', 2400 ); } );
The only difference between these images is their pixel values and image size.
Please let us know if you notice anything we might have overlooked.
Thanks,
Mahesh Thorat
#8
@
5 months ago
@maheshmthorat as you're seeking to scale and crop the images, please change your code to do this:
<?php add_action( 'after_setup_theme', function() { add_image_size( 'custom_size_2400', 2400, 2400, true ); } );
The code specifies the width (2400), height (2400), and sets it to crop (true
).
Can you retest please?
#9
follow-up:
↓ 10
@
5 months ago
Hi @hellofromTonya,
Thank you for your code. This time, the image does get created with variations.
However, I tried using this image (https://drive.google.com/file/d/1zEQ8Z-07EXfjvcrDKJCQBsAV8pPg0ZrD/view?usp=drive_link) and it couldn't create any variations. Could you please download this image and check if it works on your side as well?
I've tried it on different servers without success.
Thanks,
Mahesh Thorat
#10
in reply to:
↑ 9
@
5 months ago
- Keywords reporter-feedback removed
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Replying to maheshmthorat:
However, I tried using this image (https://drive.google.com/file/d/1zEQ8Z-07EXfjvcrDKJCQBsAV8pPg0ZrD/view?usp=drive_link) and it couldn't create any variations. Could you please download this image and check if it works on your side as well?
I've tried it on different servers without success.
I tested that image in a local test environment, same as I did the other tests in this ticket. It worked for me.
Using this test code:
<?php add_action( 'after_setup_theme', function() { add_image_size( 'custom_size_2400', 2400, 2400, true ); } );
Here's a list from the uploads
directory:
pexels-cottonbro-5658531.jpg pexels-cottonbro-5658531-150x150.jpg pexels-cottonbro-5658531-200x300.jpg pexels-cottonbro-5658531-683x1024.jpg pexels-cottonbro-5658531-768x1152.jpg pexels-cottonbro-5658531-1024x1536.jpg pexels-cottonbro-5658531-1365x2048.jpg pexels-cottonbro-5658531-2400x2400.jpg pexels-cottonbro-5658531-scaled.jpg pexels-cottonbro-5658531.jpg
Notice, it scaled and cropped to 2400 x 2400, pexels-cottonbro-5658531-2400x2400.jpg
.
As there are multiple "can't reproduce" reports, I suspect the issue you're experiencing is due to something outside of WordPress Core's source code.
Please note, this Trac is used for the development of the WordPress software, not for assistance with individual sites or plugins. You can find people who are able to assist with your site in the WordPress support forums.
I've closed this ticket as invalid
, which is Trac's unfriendly term to indicate I've referred you to the support team.
#11
@
5 months ago
Hi @hellofromTonya
I have already asked on forum.
https://wordpress.org/support/topic/image-upload-handling-automatic-resizing-for-large-images/#post-17978218
But did not receive such helpful response.
Now created new topic here - https://wordpress.org/support/topic/image-upload-handling-automatic-resizing-for-large-images-2/
Hello @maheshmthorat,
Welcome to WordPress Core's Trac.
I'm doing 6.6.x triage today. Resetting the
Version
as 6.6.1 did not ship changes that might be affecting the reported issue. Once the root cause is identified, then the version that introduced it can be set.