Bug 134497 - PNG not exported with the same dimensions
Summary: PNG not exported with the same dimensions
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Draw (show other bugs)
Version:
(earliest affected)
3.4.0 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Graphics-Export
  Show dependency treegraph
 
Reported: 2020-07-04 12:48 UTC by taro
Modified: 2024-06-21 12:40 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:


Attachments
Position and size dialog, Export dialog (125.79 KB, application/pdf)
2020-10-23 06:47 UTC, Robo Pluhar
Details
PNG Options dialogue - export size in px vs original pixture size in px (111.13 KB, image/png)
2020-10-23 10:50 UTC, Robo Pluhar
Details
PNG image for testing, 742x300px (7.62 KB, image/png)
2021-07-28 14:45 UTC, Robo Pluhar
Details
Inage properties (PhotoFiltre, IrfanView) (171.25 KB, image/png)
2021-07-28 18:21 UTC, Robo Pluhar
Details
Draw: Resolution settings for PNG export (227.40 KB, image/png)
2024-06-21 07:37 UTC, Robo Pluhar
Details
Resolution test comparison - output (left), original (right). (478.49 KB, image/png)
2024-06-21 07:44 UTC, Robo Pluhar
Details
Resolution test comparison 2 - output (left), original (right). (279.79 KB, image/png)
2024-06-21 07:54 UTC, Robo Pluhar
Details
Libre office Draw test file (185.43 KB, application/vnd.oasis.opendocument.graphics)
2024-06-21 08:05 UTC, Robo Pluhar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description taro 2020-07-04 12:48:52 UTC
Description:
draw で PNG 画像を挿入した図形をPNG形式でエクスポートすると、挿入した画像が乱れて正常に表示されないことがある。

Actual Results:
画像が壊れてエクスポートされる。

Expected Results:
画像が壊れずにエクスポートされる。


Reproducible: Sometimes


User Profile Reset: No


OpenGL enabled: Yes

Additional Info:
[Information automatically included from LibreOffice]
Locale: ja
Module: TextDocument
[Information guessed from browser]
OS: Windows (All)
OS is 64bit: yes
Comment 1 Julien Nabet 2020-07-05 09:01:15 UTC
Could you give a try to last stable LO version 6.4.5?

Also, do you have this behaviour for any image or just specific images?
Comment 2 V Stuart Foote 2020-07-05 14:36:47 UTC
from Google translate gloss...
<clip>
Description:
When you export a PNG image with a PNG image inserted in draw in PNG format, the inserted image may be distorted and may not be displayed normally.

Actual Results:
The image is corrupted and exported.

Expected Results:
The image is exported without corruption.
</clip>
Comment 3 Robo Pluhar 2020-10-23 06:47:14 UTC
Created attachment 166653 [details]
Position and size dialog, Export dialog

I have probably the same experience. My LO is:
Version: 6.4.6.2
Build ID: 1:6.4.6-0ubuntu0.20.04.1
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: gtk3; 
Locale: cs-CZ (en_DK.UTF-8); UI-Language: en-US
Calc: threaded

Example: 
1) A source PNG image has resolution 742x300px.
2) PNG is inserted into Draw by drag-and-drop.
3) Right click to PNG image > original size.
4) In the Position and Size dialog I can see size 742.1 pt x 300.0 pt.
5) CTRL-A (select all). Selected area is the same as the picture (there is nothig outside the original picture).
6) File > Export... 
7) In the Export dialog check Selection, output format: PNG.
8) PNG Options dialog appears - strangely enough the size is: 742.41 x 299.96 points, resolution 37 pixels/cm. Click OK.
9) Exported image has resolution 990x400px (what can I see is the same what was previously selected - different resolution is not caused by exporting more than it is supposed). And the picture is blurred of course.

BTW: When I am in the step 8) and change the width of the picture to 742 points (instead of 742.41), and click to the height field, LO Draw crashes immediately.

So I can see only one way how to export PNG image without any distortion:
1) Zoom the picture to 100% size.
2) Make a screenshot.
And for small pictures it is actually simpler way than use export dialog (as export dialog does not remember my settings so I have to check "Selection" and change export format from JPG to PNG during every export).
Comment 4 Robo Pluhar 2020-10-23 10:50:24 UTC
Created attachment 166659 [details]
PNG Options dialogue - export size in px vs original pixture size in px

Additional info:
I realized that I can set units to pixels in the PNG Options dialogue:
1) Before I set size to pixels, there is default size 990 x 400 pixels.
2) When I change Width to 724 pixels, LO changes Height to 293 pixels (instead of 724x300 px, which is original picture resolution, see attachment).
3) Exported picture has size 724x293px. 

Expected results:
* when exported picture is in its original size (in the drawing), the PNG Options dialogue should use the same size in pixels by default,
* aspect ratio should be preserved.

Tested on Xubuntu 20.04, LO Version: 7.0.2.2
Build ID: 0b4360524e0359c479b908cb9f8f3765ab0cc7ad
CPU threads: 2; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 5 Buovjaga 2021-07-27 10:47:55 UTC
We need an example png to test
Comment 6 Robo Pluhar 2021-07-28 14:45:07 UTC
Created attachment 173920 [details]
PNG image for testing, 742x300px

There is a picture 742x300 px in the attachment. In my previous comment (nr. 4) I made a mistake and used 724px instead of 742. I am sorry for that.
Now, when I use correct width 742px in the "PNG Options" dialogue LO calculates 300px height (which is correct and aspect ratio is preserved).

So expected result is just one:
* when exported picture is in its original size (in the drawing), the PNG Options dialogue should use the same size in pixels by default.
Comment 7 Buovjaga 2021-07-28 16:23:00 UTC
(In reply to Robo Pluhar from comment #6)
> Created attachment 173920 [details]
> PNG image for testing, 742x300px
> 
> There is a picture 742x300 px in the attachment. In my previous comment (nr.
> 4) I made a mistake and used 724px instead of 742. I am sorry for that.
> Now, when I use correct width 742px in the "PNG Options" dialogue LO
> calculates 300px height (which is correct and aspect ratio is preserved).
> 
> So expected result is just one:
> * when exported picture is in its original size (in the drawing), the PNG
> Options dialogue should use the same size in pixels by default.

This image has a weird DPI. If I open it with GIMP and view Image - Properties, it shows DPI as 2,834×2,834 px/mm. GIMP does export it correctly, however, and even preserves the DPI.

With LibreOffice, to export an image in its original size, you need to right-click the image and select Original size first. If we do it in this case, the exported resolution is 990x400 and the DPI will change to 72x72 ppi.

So LibreOffice should learn to behave as smartly as GIMP.

NixOS
Version: 7.3.0.0.alpha0+ / LibreOffice Community
Build ID: 67e47070a7580a17804adce812cc2f98bfe7b51f
CPU threads: 16; OS: Linux 5.13; UI render: default; VCL: x11
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: threaded
Comment 8 Robo Pluhar 2021-07-28 18:21:10 UTC
Created attachment 173933 [details]
Inage properties (PhotoFiltre, IrfanView)

(In reply to Buovjaga from comment #7)
> This image has a weird DPI. If I open it with GIMP and view Image -
> Properties, it shows DPI as 2,834×2,834 px/mm. GIMP does export it
> correctly, however, and even preserves the DPI.
> 
> With LibreOffice, to export an image in its original size, you need to
> right-click the image and select Original size first. If we do it in this
> case, the exported resolution is 990x400 and the DPI will change to 72x72
> ppi.

I opened the image in PhotoFiltre and IrfanView and both of them claim that the DPI is 72x72, and ImageMagick says:

$ identify -verbose -units PixelsPerInch ExStudPr_17_predmet_planu_plain.png
Image: ExStudPr_17_predmet_planu_plain.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 742x300+0+0
  Resolution: 71.98x71.98
  Print size: 10.3084x4.16782
  Units: PixelsPerInch
....
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Comment 9 Buovjaga 2021-07-28 18:40:51 UTC
(In reply to Robo Pluhar from comment #8)
> Created attachment 173933 [details]
> Inage properties (PhotoFiltre, IrfanView)
> 
> (In reply to Buovjaga from comment #7)
> > This image has a weird DPI. If I open it with GIMP and view Image -
> > Properties, it shows DPI as 2,834×2,834 px/mm. GIMP does export it
> > correctly, however, and even preserves the DPI.
> > 
> > With LibreOffice, to export an image in its original size, you need to
> > right-click the image and select Original size first. If we do it in this
> > case, the exported resolution is 990x400 and the DPI will change to 72x72
> > ppi.
> 
> I opened the image in PhotoFiltre and IrfanView and both of them claim that
> the DPI is 72x72, and ImageMagick says:
> 
> $ identify -verbose -units PixelsPerInch ExStudPr_17_predmet_planu_plain.png
> Image: ExStudPr_17_predmet_planu_plain.png
>   Format: PNG (Portable Network Graphics)
>   Mime type: image/png
>   Class: DirectClass
>   Geometry: 742x300+0+0
>   Resolution: 71.98x71.98
>   Print size: 10.3084x4.16782
>   Units: PixelsPerInch
> ....
> Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org

Hmm, you are right. 2,834×2,834 px/mm is the same approximation as 72x72 ppi.
Comment 10 Buovjaga 2021-08-14 14:18:50 UTC
Already behaves like this in oldest of Linux 43all bibisect repo
Comment 11 QA Administrators 2023-08-15 03:15:10 UTC Comment hidden (obsolete)
Comment 12 Stéphane Guillou (stragu) 2024-06-18 06:46:18 UTC
I think there is some confusion in this report due to the poor UX of the dialog, and how resolution and size interact in it, see bug 144195.

taro's original might have been that the aspect ratio is lost ("distorted" as translated in comment 2) and I'm wondering if it's related to bug 122155.

Otherwise, a relevant report is bug 132959 and related: metadata is not written to file as it should.

taro, Robo, Buovjaga, what do you think?
Comment 13 Robo Pluhar 2024-06-21 07:36:36 UTC
(In reply to Stéphane Guillou (stragu) from comment #12)

I made new tests on:
Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 16; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: cs-CZ (en_DK.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.4
Calc: threaded

and:
* pixel size of the exported image seems to be OK,
* 72DPI seems to be OK,
* exported picture is stil blurred.

I do not see any connection to other bugs you mentioned:
* Bug 144195: I am able to set pixel size correctly and DPI seems to be correct (in PhotoFiltre).
* Bug 122155: I do not experience any problems with margins (well, I export selected objects only).
* Bug 132959: I do not see any metadata problem.

But I agree that UX of the export is poor - for me it is difficult to set up all export setting correctly. For more pictures would be very tidious too.
But this is just an academic question while exported picture is blurred (so useless). 
Still the only way how to export PNG is to make screenshot of Draw. 

I am going to add attachments from my test.
Comment 14 Robo Pluhar 2024-06-21 07:37:57 UTC
Created attachment 194872 [details]
Draw: Resolution settings for PNG export
Comment 15 Robo Pluhar 2024-06-21 07:44:59 UTC
Created attachment 194873 [details]
Resolution test comparison - output (left), original (right).

Pixel size and DPI seems to be the same, but exported picture is blurred.

Oh no, how blind was I! I have just noticed, that the output picture is different - there is line of white pixels on the bottom and on the right of the picture. That is the reason why the picture is blurred.
Comment 16 Robo Pluhar 2024-06-21 07:54:11 UTC
Created attachment 194874 [details]
Resolution test comparison 2 - output (left), original (right).

Finally not blurred image: I changed pixel size of the exported picture - add one pixel for width and height and the size of the image is exported as was set in the dialog and the image is not blurred (because of the extra white lines top and bottom).
So when I crop the output picture (cut out the white on the bottom and right side), I finally get what I wanted.
Comment 17 Robo Pluhar 2024-06-21 08:05:31 UTC
Created attachment 194875 [details]
Libre office Draw test file
Comment 18 V Stuart Foote 2024-06-21 11:10:10 UTC
@Mike, Quikee given comment 15 and comment 16 any chance the PNG export at original size has Rectangle::GetWidth() Rectangle::GetHeight() with missing +1 handling? 

Similar to bug 98896 for single monitor slide show, resolved with

https://gerrit.libreoffice.org/c/core/+/67941