Ticket #2199 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

Image Upload uses wrong size when sending to editor

Reported by: Kelson Assigned to: ryan
Priority: normal Milestone:
Component: Administration Version: 2.0
Severity: normal Keywords: bg|has-patch
Cc:

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

thumb-splint.diff (2.5 kB) - added by skeltoac on 01/05/06 22:56:38.

Change History

01/05/06 05:34:05 changed by thecompjoe

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.

01/05/06 22:56:24 changed by skeltoac

  • keywords changed from image upload size to bg|has-patch.
  • owner changed from anonymous to ryan.
  • milestone set to 2.1.

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.

01/05/06 22:56:38 changed by skeltoac

  • attachment thumb-splint.diff added.

01/05/06 23:33:51 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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

01/06/06 01:18:04 changed by ryan

  • milestone changed from 2.1 to 2.0.1.

01/17/06 23:36:27 changed by remixer

  • status changed from closed to reopened.
  • resolution deleted.

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


01/18/06 01:01:47 changed by skeltoac

  • status changed from reopened to closed.
  • resolution set to fixed.

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

11/30/06 19:41:49 changed by

  • milestone deleted.

Milestone 2.0.1 deleted