Bug 127854 - Add ability to keep vector image and compress replacement image in image compression dialog
Summary: Add ability to keep vector image and compress replacement image in image comp...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Images
  Show dependency treegraph
 
Reported: 2019-09-29 08:09 UTC by Gellért Gyuris
Modified: 2020-05-22 10:06 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample files (502.18 KB, application/zip)
2020-04-23 12:37 UTC, Gellért Gyuris
Details
Sample files with linked vector images (490.47 KB, application/zip)
2020-04-24 11:15 UTC, Gellért Gyuris
Details
New sample (16.82 MB, application/x-7z-compressed)
2020-05-12 21:38 UTC, Gellért Gyuris
Details
Testing various ODF editors (1.14 MB, application/x-7z-compressed)
2020-05-22 10:06 UTC, Gellért Gyuris
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gellért Gyuris 2019-09-29 08:09:36 UTC
Description:
For vector images (SVG, PDF) the user should be able to select in image compression dialog: 
1. keep vector image untouched and compress replacement image only
2. replace vector image with compressed bitmap (current behavior)

Steps to Reproduce:
1. Create a new document.
2. Insert any SVG file as image. (eg. first arrow from Gallery)
3. Select it, and choose "Compress..." from context menu

Actual Results:
After compressing SVG file is replaced with a compressed bitmap.

Expected Results:
When user selects a vector image (SVG, PDF) in image compression dialog there should be an option:
[] compress replacement image only
[] replace vector image with compressed bitmap

2nd option is the current behavior, it's implemented. When user selects 1st option LO should be keep vector image untouched and compress replacement image with given options.


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Gellért Gyuris 2019-10-21 18:11:16 UTC
Workaround: Completely disable creating replacement images in Expert Configuration: org.openOffce.Office.Common > Save > Grapchics > AddReplacementImages: false
Comment 2 Heiko Tietze 2020-04-23 09:18:14 UTC
I don't see a point in compressing SVGs and expecting it to remain ("keep vector image untouched"). What's your use case, what do you want to achieve and why?
Comment 3 Gellért Gyuris 2020-04-23 12:35:50 UTC
Thanks you for the replay, Heiko!

What do you want to achieve?
When inserted image is a vector format (SVG, PDF...) I want to compress the replacement image only, not the original vector file. This is currently not possible, because the image compression dialog replaces the original vector file with a bitmap copy.

Why? Use case
I have SVG/PDF files with huge canvas (not image size): 1×2 m roll-up, large  outdoor boards for displaying advertisements (4×2,75 m). When I insert these drawings, it creates replacement images with huge file size (even if the vector images are only linked). I want to compress the replacement image size to reduce ODT document size as this image compression feature designed for.

It is not a good option to replace the vector with a bitmap, I want to see the vector file in PDF output, therefore I want to preserve vector format in ODT. I want to compress the replacement image only.

I hope I was able to explain it.
Comment 4 Gellért Gyuris 2020-04-23 12:37:37 UTC
Created attachment 159845 [details]
Sample files
Comment 5 Heiko Tietze 2020-04-24 08:41:46 UTC
Thanks for the clarification and the sample files. Some more questions:
* If you have the vector graphic why do you want/need to convert/compress it?
* Would it be a feasible solution to do the trick with linked images? Don't see where I can compress the image when the SVG is inserted per link but that could be made possible. Point is that I struggle with the Heisenberg-situation of compressed / not compressed. If you process data, in general, you keep the raw sources as backup.
Comment 6 Gellért Gyuris 2020-04-24 11:13:39 UTC
Thank you for thinking with me.

If you have the vector graphic why do you want/need to convert/compress it?
I want to compress not the vector data (SVG, PDF) but the automatically generated _replacement image_ (PNG). In general the replacement image is a good solution but when the vector's canvas has a big real size (several meters), the rasterized replacement image has a huge file size too. It doesn't matter if the real size of the vector file is 1 cm or 10 m. File size is the same. But for a bitmap the file size will be quite different. I want to avoid this huge replacement images. Since AddReplacementImages=true is the default option, the obvious solution is to compress them.

I think for vector files this is the "logical" behavior: do not replace the vector data (this is data loss) but compress the replacement image.

Would it be a feasible solution to do the trick with linked images?
Sorry, I don't understand fully the question. As I tested, it doesn't matter if the vector file embedded or linked, replacement images are generated by LibreOffice.
Comment 7 Gellért Gyuris 2020-04-24 11:15:16 UTC
Created attachment 159896 [details]
Sample files with linked vector images
Comment 8 Heiko Tietze 2020-04-27 11:39:02 UTC
(In reply to Gellért Gyuris from comment #6)
> If you have the vector graphic why do you want/need to convert/compress it?
> I want to compress not the vector data (SVG, PDF) but...

Sure, the question was, if you have a nice vector graphic why do you want to convert it into a raster graphic (that needs compression). I'm turning the question around with a workflow in mind where no raster bitmap nor any compression is needed. In other words: if you keep the SVG, why do you need a bitmap?
Comment 9 Gellért Gyuris 2020-04-28 20:35:29 UTC
> if you keep the SVG, why do you need a bitmap?

Oh, that is a good question!

I do not need any bitmap, but LibreOffice creates it automatically when I insert the vector file! The automatic replacement images were introduced 5-6 years ago. I read first time about them in Miklós' blog post: https://vmiklos.hu/blog/lo-insert-pdf-image.html

I can understand that is a good solution to have a fallback image when one have to open the document in another editor. But when the vectors' canvas is huge we have disadvantages.

If I must have a replacement image in the stored document, I want ability to compress it.
Comment 10 Heiko Tietze 2020-04-30 08:56:11 UTC
Both SVG and PNG are stored in the document. It looks like this

<draw:image loext:mime-type="image/svg+xml">
<office:binary-data>
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+
...
<draw:image loext:mime-type="image/png">
<office:binary-data>
iVBORw0KGgoAAAANSUhEUgAAAVoAAABCCAYAAAAWox40AAApCUlEQVR4nO2dBZAURxuGA9zh
...

I cannot imagine a sane workflow where the converted/compressed PNG can be reassigned/recompressed from the SVG. What definitely works is when the PNG would be solely saved for compatibility reason and the SVG is being used in the document.

However, the issue remains that documents grow rapidly and I wonder if a compatibility flag makes sense. Something like Tools > Options > Writer > Compatibility "[ ] Save vector graphics as PNG" (off by default, IMHO). 

What do you think, Miklos?
Comment 11 Miklos Vajna 2020-04-30 09:03:51 UTC
Michael Stahl may have an opinion on this; the answer may depend on the ODF version. Perhaps support for SVG is a reasonable expectation for ODF 1.3, but not for ODF 1.2.
Comment 12 Michael Stahl (allotropia) 2020-05-04 08:52:29 UTC
i dont think its a good idea at this point to remove the PNG fallback that is automatically generated at ODF export.

for OOo derived applications both AOO and LO can import SVG since 2011 or so, but i have no idea about others like e.g. MS Office, Google Docs, etc.

maybe we can do that in a couple years.
Comment 13 Heiko Tietze 2020-05-04 13:46:20 UTC
How about an explicit function to remove the PNG? Something like a third radio button in the compression dialog visible on vector graphics only.
Comment 14 Regina Henschel 2020-05-04 14:03:13 UTC
(In reply to Heiko Tietze from comment #13)
> How about an explicit function to remove the PNG? Something like a third
> radio button in the compression dialog visible on vector graphics only.

There exists the global advanced setting "AddReplacementImages". Default is "true". Double-click the item toggles it to "false".

I think, that a setting "removing" should not be included in the compression dialog, because such setting would be need to be tracked in export.
Comment 15 Heiko Tietze 2020-05-04 14:04:26 UTC
(In reply to Regina Henschel from comment #14)
> There exists the global advanced setting "AddReplacementImages".

Is this sufficient for you, Gellért?
Comment 16 Tomaz Vajngerl 2020-05-04 14:05:16 UTC
Compress dialog has nothing to do and should not have anything to do with the replacement graphic. That one is created and added during export. 

That said, in the compress graphic dialog we shouldn't allow to compress vector graphic and result with a bitmap.
Comment 17 Gellért Gyuris 2020-05-04 15:12:47 UTC
> Is this sufficient for you, Gellért?

I know about this global switch (I'm using it currently) as I mentioned previously in Comment #1. I thinks this is a workaround, not a solution, because it is not a per image or per document possibility but a global switch.
Comment 18 Cor Nouws 2020-05-05 18:29:41 UTC
(In reply to Tomaz Vajngerl from comment #16)
> Compress dialog has nothing to do and should not have anything to do with
> the replacement graphic. That one is created and added during export. 
> 
> That said, in the compress graphic dialog we shouldn't allow to compress
> vector graphic and result with a bitmap.

(In reply to Gellért Gyuris from comment #0)
> ..
> Expected Results:
> When user selects a vector image (SVG, PDF) in image compression dialog
> there should be an option:
> [] compress replacement image only

Why would you use that option, Gellért, if you want to keep the SVG in the file as well?
Comment 19 Gellért Gyuris 2020-05-12 21:38:17 UTC
Created attachment 160735 [details]
New sample

Cor Nouws, I'm trying to explain again, but I'm afraid that I'm just repeating myself. I hope I can answer your question: I want to avoid big and unnecessary PNG replacement images for embedded vector images. 

See attached sample: There is a document with 9 embedded roll-ups (with 85 cm × 200 cm). LibreOffice normally generates a replacement PNG for every embedded vector image. In these examples:
- for 55 kB SVGs LO generates 2,5 MB PNGs, or
- for 2,1 MB PDFs LO generates 21,1 MB PNGs.

There are an expert switch (org.openOffce.Office.Common > Save > Grapchics > AddReplacementImages: false) to completely exclude generating these replacement images, but this is a hidden feature and a global switch, not a per document or per image switch. 

I found that image compressing feature would be the best solution:
- I think, the current behavior isn't the best: replace vector file with a bitmap and compress the bitmap...
- This feature would be better if preserves the original vector and compress the replacement images. This is a feature request.
- Or with an option we can preserve both behavior as I suggested above.

Maybe this isn't a good idea. I'm just a user, not a developer. Maybe someone has a better idea. Do you know a better solution how to prevent huge replacement files from being created?
Comment 20 QA Administrators 2020-05-13 03:51:55 UTC Comment hidden (obsolete)
Comment 21 Heiko Tietze 2020-05-13 09:53:11 UTC
(In reply to Michael Stahl (CIB) from comment #12)
> i dont think its a good idea at this point to remove the PNG fallback that
> is automatically generated at ODF export.
> 
> for OOo derived applications both AOO and LO can import SVG since 2011 or
> so, but i have no idea about others like e.g. MS Office, Google Docs, etc.
> 
> maybe we can do that in a couple years.

The use case described in this enhancement request is reasonable. And many if not most users don't bother about AOO or the like and just use still/fresh LibreOffice. So my take on all this is to introduce an option that might be switched on but allows users like Gellért to disable the PNG conversion.
Comment 22 Michael Stahl (allotropia) 2020-05-13 17:58:23 UTC
(In reply to Heiko Tietze from comment #21)
> (In reply to Michael Stahl (CIB) from comment #12)
> > i dont think its a good idea at this point to remove the PNG fallback that
> > is automatically generated at ODF export.
> > 
> > for OOo derived applications both AOO and LO can import SVG since 2011 or
> > so, but i have no idea about others like e.g. MS Office, Google Docs, etc.
> > 
> > maybe we can do that in a couple years.
> 
> The use case described in this enhancement request is reasonable. And many
> if not most users don't bother about AOO or the like and just use
> still/fresh LibreOffice. So my take on all this is to introduce an option
> that might be switched on but allows users like Gellért to disable the PNG
> conversion.

it would be great if somebody could research which ODF applications can import SVGs and which can't.

i don't have time to do this.
Comment 23 Gellért Gyuris 2020-05-22 10:06:21 UTC
Created attachment 161126 [details]
Testing various ODF editors

Small research:

- Google Docs: 
  - Can't insert SVG image. Error: Not supported file type.
  - Can import LibreOffice's ODT and use replacement PNG image.
  - Export replacement image to ODT or PDF.

- Microsoft Office 365
  - Can't insert SVG image. Error: Not supported file type.
  - Error opening LibreOffice's ODT. Can't handle replacement PNG image.

- Apache OpenOffice (4.1.7):
  - Can insert SVG images. Creates replacement PNG file too.
  - Can export to OTD (replacement SVG too) and to PDF.
  - Can open LibreOffice's ODT and save it correctly.

- AbiWord (3.0.2)
  - Can insert SVG image. Inserts only SVG data, without replacement image.
  - Can export to ODT.
  - Can't export to PDF.

- FreeOffice TextMaker (976)
  - No support for SVG images in Free version.
  - Can import LibreOffice's ODT and use replacement PNG image.

Is it enough? Which editors should I test besides these?