WordPress.org

Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#2199 closed defect (bug) (fixed)

Image Upload uses wrong size when sending to editor

Reported by: Kelson Owned by: ryan
Milestone: Priority: normal
Severity: normal Version: 2.0
Component: Administration Keywords: bg|has-patch
Focuses: Cc:
PR Number:

Description

Sending an image to the editor with "Using Original" adds width and height attributes using the size of the thumbnail instead of the original image. It does insert the right SRC attribute (i.e. it points to image.jpg and not image.thumbnail.jpg), and removing the width and height attributes allows you to show the image at the original size, but if you're going to insert metadata, it should be the right metadata.

Observed using WordPress 2.0 with the plain-text editor and Firefox 1.5.

Attachments (1)

thumb-splint.diff (2.5 KB) - added by skeltoac 14 years ago.

Download all attachments as: .zip

Change History (8)

#1 @thecompjoe
14 years ago

As discussed at http://wordpress.org/support/topic/53640:

The code on lines 81-85 in wp-admin/inline-uploading.php appears to determine the size of the thumbnail file that WP generates:

if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
$thumb = wp_create_thumbnail($file, 128);
elseif ( $imagedata['height'] > 96 )
$thumb = wp_create_thumbnail($file, 96);

But from what I can tell, this code does not actually affect the dimension attributes WP uses when inserting the image. For example, changing the code in inline-uploading.php will result in a thumbnail file with larger dimensions on your server, say 256x192, but when browsing and inserting the thumbnail into the post, WP will still apply the code using something like <img src="pic.jpg" width="128" height="96 />. This is where admin-functions.php comes into play.

Lines 1771-1778 look something like this:

function wp_shrink_dimensions($width, $height, $wmax = 128, $hmax = 96) {
if ( $height <= $hmax && $width <= $wmax )
return array($width, $height);
elseif ( $width / $height > $wmax / $hmax )
return array($wmax, (int) ($height / $width * $wmax));
else
return array((int) ($width / $height * $hmax), $hmax);
}

and lines 1863-1870 look something like this:

function get_udims($width, $height) {
if ( $height <= 96 && $width <= 128 )
return array($width, $height);
elseif ( $width / $height > 4 / 3 )
return array(128, (int) ($height / $width * 128));
else
return array((int) ($width / $height * 96), 96);
}

Now I've tinkered around with it for a while, replacing the 128 and 96 values with larger integers. I have had limited success in which inserted images now appear with their original dimensions; however, when opting to insert thumbnails, the "thumbnails" are also stretched to the larger dimensions of the original, which causes them to be massively pixelated.

I am by no means up to snuff on PHP and coding in general, so I have a feeling that if someone more knowledgable were to take a look at the source in these files, there is a way to alter the dimension integers appropriately so that original images and thumbnails are displayed with their correct dimensions respectively.

#2 @skeltoac
14 years ago

  • Keywords bg|has-patch added; image upload size removed
  • Milestone set to 2.1
  • Owner changed from anonymous to ryan

innerHTML wasn't responding to changes in src attribute.

This patch removes height and width attributes during Send To Editor function, and fixes image to be sent with the proper src attribute.

#3 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [3407]) Send to editor fix ups. fixes #2199

#4 @ryan
14 years ago

  • Milestone changed from 2.1 to 2.0.1

#5 @remixer
14 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I just installed the latestest update 3407 and im getting these.


Warning: Cannot modify header information - headers already sent by (output started at /usr/home/ec1/blog/htdocs/wp-admin/inline-uploading.php:2) in /usr/home/ec1/blog/htdocs/wp-admin/inline-uploading.php on line 139


#6 @skeltoac
14 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

New bug not related to this ticket. You need to open a new ticket for this bug.

#7 @(none)
13 years ago

  • Milestone 2.0.1 deleted

Milestone 2.0.1 deleted

Note: See TracTickets for help on using tickets.