Bug Hunting Session
Bug 83073 - Images pasted / opened from HTML at incorrect size
Summary: Images pasted / opened from HTML at incorrect size
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
4.3.0.4 release
Hardware: x86 (IA32) Windows (All)
: medium normal
Assignee: Caolán McNamara
URL:
Whiteboard: target:4.5.0 target:4.3.7 target:4.4.1
Keywords: regression
Depends on:
Blocks:
 
Reported: 2014-08-25 19:55 UTC by Mark Bourne
Modified: 2015-04-13 19:43 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
html-img-size-demo.html for steps to reproduce (56.55 KB, text/html)
2014-09-28 20:50 UTC, Mark Bourne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Bourne 2014-08-25 19:55:09 UTC
Copying images from a web page and pasting into a LibreOffice HTML Document, the pasted images are not always at the correct size. In some cases, they are only 2cm x 1cm; this appears to be the size of the initial placeholder, which is then replaced with the image content and usually resized to suit, but in some cases the resize does not seem to occur. Format > Image > Type > Original Size sets the images to too large a size, and saving from LibreOffice as HTML leads to pixel sizes larger than the original image.

Steps to reproduce:

In LibreOffice:
1) Create a new HTML Document (File > New > HTML Document).

In a web browser:
2) Open the attached HTML document (html-img-size-demo.html). This contains two images, one using a data: URI to embed image data in the HTML file, the other using a http: URI to download the same image from xkcd.com; both are 727 x 233 pixels.

3) Copy the first (data: URI) image (right-click > Copy Image or similar depending on browser).

In LibreOffice:
4) Paste into the HTML document. The image is pasted at 2.00 x 1.00 cm. Saving the document leads to an <img> tag with width="75" height="38" (pixels).

5) Select the image and go to Format > Image > Type > Original Size. The image size is set to 25.64 x 8.22 cm. Saving the document leads to an <img> tag with width="969" height="311" (pixels); this is not the original image size.

In a web browser:
6) Copy the second (http: URI) image (right-click > Copy Image or similar depending on browser).

In LibreOffice:
7) Paste into the HTML document. A 2.00 x 1.00 cm placeholder initially appears, but it changes to 19.24 x 6.16 cm once the image is downloaded. Saving the document leads to an <img> tag with width="727" height="233" (pixels); this is the correct original image size.

8) Select the image and go to Format > Image > Type > Original Size. The image size is set to 25.64 x 8.22 cm, and saving the document leads to an <img> tag with width="969" height="311" (pixels); this is not the original image size.

9) Close the HTML document.

10) Open the attached HTML document (html-img-size-demo.html) in LibreOffice. Both images are 2.00 x 1.00 cm. Saving the document leads to <img> tags with width="75" height="38" (pixels).

11) For each image in turn, select the image and go to Format > Image > Type > Original Size. Both image sizes are set to 25.64 x 8.22 cm, and saving the document leads to <img> tags with width="969" height="311" (pixels); this is not the original image size.


The same behaviour is observed using LibreOffice Writer with a text document. In that case, it is necessary to ensure the page size is large enough (e.g. set to A3 landscape) to avoid capping the size, and also need to use Paste Special > HTML format since the default is to paste as bitmap.


Expected behaviour:
- Pasted images (and those from opening the HTML file) should be the size of the source image.
- Format > Image > Type > Original Size should set the image size to that of the source image.
- Saving the resulting LibreOffice HTML document should lead to pixel dimensions matching the original image.


There are possibly a couple of different issues here:
1. The initial 2.00 x 1.00 cm placeholder is not always resized after loading the image.
2. It appears that a scale of 72 pixels/inch is used when determining the "original image size", but a scale of 96 pixels/inch is used when determining the pixel size for the <img> tag on saving the HTML document.


Tested using:
- Windows Vista, 32-bit
- LibreOffice 4.3.0.4
- Copying from multiple web browsers:
  - Mozilla SeaMonkey 2.26.1
  - Internet Explorer 9.0.8112.16421
  - Google Chrome 36.0.1985.143
Comment 1 Yousuf Philips (jay) (retired) 2014-09-28 18:56:02 UTC
Hello Mark,

Thank you for filing the bug. You mentioned in your instructions that opening an attachment, but unfortunately you didnt provide it.
Comment 2 Mark Bourne 2014-09-28 20:50:29 UTC
Created attachment 107025 [details]
html-img-size-demo.html for steps to reproduce

Sorry about that. Should now be attached.
Comment 3 Yousuf Philips (jay) (retired) 2014-09-29 05:10:35 UTC
Thanks for the file. I went through the instructions and see that whenever you click original size, it stretch the image to the size of the window, so if i had the sidebar open, it was smaller than when it was closed. So with the URI it should extract its pixel size and using that size when pasting. I've seen similar circumstances when pasting an svg from a webpage did a similar thing into a regular word document, though i'm not sure if it was URI or URL.

Tested on master.

Version: 4.4.0.0.alpha0+
Build ID: df73f4115cfe4d07e4159adf087571687eb173ec
TinderBox: Linux-rpm_deb-x86@45-TDF, Branch:master, Time: 2014-09-25_23:36:54
Comment 4 Caolán McNamara 2015-02-09 14:50:49 UTC
possibly a regression in the 8da21eca455134a1d017893a9b1d26f827fba185..da21f7da44dc577a08ea3bc210083dc8decf18bc range
Comment 5 Caolán McNamara 2015-02-10 09:48:41 UTC
This is (somehow) triggered by

commit 38faee21e0b874359246e513b0a8c0af399a864d
Author: Matúš Kukan <matus.kukan@collabora.com>
Date:   Tue Sep 23 14:40:01 2014 +0200

    Do not link html images only when pasting from clipboard (bnc#580834)
    
    Change-Id: I020c4e6ed6d468e553dedd7c91979b081d6b4725
Comment 6 Commit Notification 2015-02-10 10:21:40 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=4327ee505f8507f653c8f4db9ac7503db2e15c3a

Resolves: tdf#83073 use loaded graphic's width/height as defaults

It will be available in 4.5.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 7 Michael Stahl (CIB) 2015-02-11 15:21:06 UTC
add keyword according to comment #5
Comment 8 Commit Notification 2015-02-11 15:38:26 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-3":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=d330d1cb36b81026e448dc371075b7bc8c75d33e&h=libreoffice-4-3

Resolves: tdf#83073 use loaded graphic's width/height as defaults

It will be available in 4.3.7.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 9 Commit Notification 2015-02-11 15:38:38 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-4":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=dd53735c5fe98fa4f8da4bf214a04b7883bf73c8&h=libreoffice-4-4

Resolves: tdf#83073 use loaded graphic's width/height as defaults

It will be available in 4.4.2.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 10 Commit Notification 2015-02-20 13:03:19 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-4-1":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=f2c562a64da925d96260939181574770224dadad&h=libreoffice-4-4-1

Resolves: tdf#83073 use loaded graphic's width/height as defaults

It will be available in 4.4.1.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 11 Ulrich Windl 2015-04-10 06:18:04 UTC
I think this bug still is not fixed for 4.3.6.2 on Windows 7:
I copied all of a HTML mail message and pasted it into writer. The HTML contains images referenced by CID: (part of the same message). The images all appear with content, but the images all seem to have size 2x1cm. In one case I checked it: When openeing the image properties and select "original size", then the image has size 17x9.26cm. I also checked the HTML: the <img> element contains no specific size attributes, so the images should be displayed in their native size (as done when viewing the HTML message in the mail program).
If you think it's a different bug, set this one to resolved again.
Comment 12 Ulrich Windl 2015-04-10 06:20:27 UTC
Is there a work-around that will set all images in a document to "original size" (without doing it one-by-one)?
Comment 13 Caolán McNamara 2015-04-13 15:05:31 UTC
Original codebot claimed that the commit will be in 4.3.7, so "4.3.6.2 still broken" isn't a surprise from that perspective.

If it is still broken in 4.3.7, or any of the other versions listed in the comments above, then feel free to file a new bug and put me on cc, but don't re-open this one unless the example of #2 fails
Comment 14 Mark Bourne 2015-04-13 19:43:45 UTC
Using LibreOffice 4.4.2 on Windows Vista, it's much improved some points from the original steps to reproduce (comment 0 with attachment from comment 2) still happen:

Step 4) Is fixed: The image copied from data: URI is pasted at the correct size, and saving results in HTML specifying the original pixel dimensions.

Step 5) Not fixed: Setting to "Original Size" sets the image to a larger size than the original size (copied from data: URI).

Step 8) Not fixed: Setting to "Original Size" sets the image to a larger size than the original size (copied from http: URI).

Step 10) Not fixed: Opening the test document in LibreOffice, the data: URI image is the correct size, but the http: URI image is 2.00 x 1.00 cm.

Step 11) Not fixed: Setting to "Original Size" sets the images to a larger size than the original size (both data: and http: URIs from opening test document).

Perhaps too many separate issues in one bug report! Should I reopen this one, or file new bugs for the outstanding parts?