Make WordPress Core

Opened 18 years ago

Closed 17 years ago

#7748 closed defect (bug) (fixed)

Black line on scaled thumbnail image

Reported by: nyoungman Owned by:
Priority: normal Milestone: 2.9
Component: Media Version: 2.6.1
Severity: normal Keywords: has-patch tested
Cc: Focuses:

Description

WordPress scales images down for thumbnails, but for some reason, in this case there is a black border on the top edge. See the bottom of this page:
http://www.globalaid.net/projects/haiti-hurricane-relief-2008/

This is part of the image, not a style (try viewing the thumbnail):
http://www.globalaid.net/wordpress/wp-content/uploads/2008/09/flooded-homes-1-240x240.jpg

And it is not part of the full image.

Attachments (1)

wp-includes-media.php.patch (724 bytes ) - added by miqrogroove 17 years ago.
Fixes flawed cropping logic and inconsistent type juggling.

Download all attachments as: .zip

Change History (21)

#1 @ShaneF
18 years ago

  • Keywords image resize image uploading added

Very interesting... looking into this.

#2 @ShaneF
18 years ago

  • Keywords dev-feedback added

Seems to not do it on the 2.7.x version. Do you have any image plugins?

#3 @DD32
18 years ago

What version of PHP & GD are you using? The GD information from the phpinfo() page would be good..

It might not be related though..

#4 follow-up: @DD32
18 years ago

I can confirm it happens when "Crop thumbnail to exact dimensions (normally thumbnails are proportional)" is disabled under trunk. (I used http://www.globalaid.net/wordpress/wp-content/uploads/2008/09/flooded-homes-1.jpg as a source image)

It appears to probably be caused by a rounding error or not enough precision somewhere.

#5 @nyoungman
18 years ago

  • Cc nyoungman added

Sorry for taking so long to come back to this.

@DD32 GD is bundled (2.0.34 compatible), all enaled with freetype 2.2.1 running on 5.2.8-0.dotdeb.1.

This is still a 2.6.5 installation of WordPress, I have not had the opportunity to test it in 2.7.x yet.

#6 in reply to: ↑ 4 ; follow-up: @Viper007Bond
17 years ago

Replying to DD32:

I can confirm it happens when "Crop thumbnail to exact dimensions (normally thumbnails are proportional)" is disabled under trunk.

I think you mean enabled.

#7 in reply to: ↑ 6 @DD32
17 years ago

Replying to Viper007Bond:

Replying to DD32:

I can confirm it happens when "Crop thumbnail to exact dimensions (normally thumbnails are proportional)" is disabled under trunk.

I think you mean enabled.

Too long ago to know what i meant now.. But Enabled would make sense.

#8 @Denis-de-Bernardy
17 years ago

  • Keywords needs-patch added; image resize image uploading dev-feedback removed
  • Milestone 2.8Future Release

#9 @Denis-de-Bernardy
17 years ago

  • Component GeneralUpload
  • Owner anonymous removed

#10 @Denis-de-Bernardy
17 years ago

  • Milestone Future Release2.9

#11 @miqrogroove
17 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

This bug is fairly obvious at wp-includes/media.php::image_resize_dimensions()

If you take an image of size 1025 and resize to 100, the size ratio is 0.09756. Dividing that ratio into 100 gives ceil(1025.01) == 1026. So even at first glance, the cropping rectangle of 1026 is larger than the original image.

#12 @miqrogroove
17 years ago

hmmm This might need more testing because on my version of PHP I couldn't reproduce the rounding error unless I set the original dimensions to something like 1025.001.

@miqrogroove
17 years ago

Fixes flawed cropping logic and inconsistent type juggling.

#13 @miqrogroove
17 years ago

  • Keywords tested added; needs-testing removed

Ah I was right. I was able to reproduce using OP's corner case:

$new_h = 240;
$orig_h = 416;
$size_ratio = $new_h / $orig_h;
$crop_h = round($new_h / $size_ratio);
var_dump($crop_h);
// float(417)

I tested and confirmed my patch will return int(416) instead of float(417) in that case.

#14 @miqrogroove
17 years ago

$new_h = 240;
$orig_h = 416;
$size_ratio = $new_h / $orig_h;
$crop_h = ceil($new_h / $size_ratio);
var_dump($crop_h);
// float(417)

ugh I hate this thing not having an edit button :(

#15 @miqrogroove
17 years ago

  • Component UploadMedia

#16 @azaozz
17 years ago

  • Resolutionfixed
  • Status newclosed

(In [12280]) Avoid a rare case of black line in cropped thumbnails, props miqrogroove, fixes #7748

#17 @azaozz
17 years ago

Don't think type casting is needed there. If it is, we should do it in the return array.

#18 @miqrogroove
17 years ago

  • Resolution fixed
  • Status closedreopened

Output still does not match function description, "Returned array matches parameters for imagecopyresampled() PHP function." If type casting is asking too much then at least correct the description to say the function returns an array of floats.

#19 @miqrogroove
17 years ago

Bump! The data type mismatch needs to be fixed, documented, or wontfix.

#20 @azaozz
17 years ago

  • Resolutionfixed
  • Status reopenedclosed

(In [12381]) Typecast to int the return of image_resize_dimensions(), fixes #7748

Note: See TracTickets for help on using tickets.