unoconv / unoserver

MIT License
495 stars 69 forks source link

Setting PNG export resolution? #85

Closed bohwaz closed 6 months ago

bohwaz commented 10 months ago

After much trial and error, I figured out (thanks to this) that you can set the exported PNG dimensions with:

unoconvert --filter-options PixelWidth=500 --filter-options PixelHeight=500  …

But it does not respect the aspect ratio of the document. I tried using a Resolution option but that does not work. Setting only the width or height doesn't work either.

I tried looking at LibreOffice source code but could not figure out where the PNG export options are. I found this: https://github.com/LibreOffice/core/blob/4ffea8f932cbad912863f7df668ed7090e6f1821/svx/source/unodraw/UnoGraphicExporter.cxx#L495

But none of the other options seemed to do anything.

wozeiliu commented 9 months ago

Your method solved my problem. I can get high-quality pngs by setting the pixel aspect ratio that meets the requirements, such as setting it to standard A4 paper size: unoconvert --filter-options PixelWidth=2479 --filter-options PixelHeight=3508 .... 😆😆😆

bohwaz commented 9 months ago

Yes but if your document is in landscape, the PNG won't have the correct size.

regebro commented 6 months ago

Indeed, setting the height and width in the filter will create an image with that height and width. Pixel aspect ratios aren't really relevant. as LibreOffice deals with documents, and not images, and hence will convert an input image into a drawing, which has a page size, and then it will squeeze your document into the stated pixel size.

If you want to convert images between different formats, I would recommend imagemagick.

bohwaz commented 6 months ago

when you specify a width, the thumbnail should keep the aspect ratio, ImageMagick doesn't have a way of knowing the aspect ratio of the document.

regebro commented 3 days ago

No, but it knows the aspect ratio of the image you exported.