Opened 11 years ago
Closed 11 years ago
#25038 closed defect (bug) (fixed)
imagecreatetruecolor fails when WP tries to make image with width of 0
Reported by: | Owned by: | nacin | |
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | major | Version: | 2.5 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
Uploading a tall narrow image will cause an error when trying to upload. I've uploaded an image with dimensions 4x1640, and when WP generates image sizes it's trying to create an image at 0x300 which throws an error in 'imagecreatetruecolor'.
I'd expect WP to skip an attempt to create an image with invalid dimensions.
No relevant plugins installed that would affect this. Problem may exist at other image ratios as well.
Attachments (3)
Change History (8)
#1
@
11 years ago
- Milestone changed from Awaiting Review to 3.7
Thanks for the example image. Really curious why it would return 0 width.
#2
@
11 years ago
- Keywords has-patch needs-testing added
- Version changed from 3.6 to trunk
The problem is the scaling code. If you try to scale a 2x20 image with the ratio 0.25, you will get a 0.5x5 image. We use integers, so we get a 0x5 image in this example. We should round up image sizes with 0px. I further fixed an equivalent bug in the preview generation of the image editor.
Maybe we should reorganize the code to avoid the redundant scaling code.
#4
@
11 years ago
- Keywords needs-testing removed
plocha's patch works well. I refreshed in 25038.diff with an updated inline comment about the check for a minimum of 1. Also removed an unnecessary change from $w = $max_width;
to $w++;
. No reason for not doing it that way, but the diff reads cleaner without it.
Sample image