Hi yall. I am writing my cv with typst and wanted to reduce the overall filesize. I have
$typst c cv.typ
$du -hs *
1.2M cv.pdf
8.0K cv.typ
2.3M cvphoto.jpg
Then I compress the jpeg with mogrify and then run typst again
$mogrify -quality 80 cvphoto.jpg
$typst c cv_johannes_lade.typ
$du -hs *
1.4M cv.pdf
8.0K cv.typ
1.2M cvphoto.jpg
You can see that the jpeg memory size almost halved but the pdf output of typst increased by 15%. How is that happening?
Eric
October 28, 2024, 10:13pm
2
Typst currently re-encodes jpeg images, and I could imagine that the new encoding is independent of any jpeg compression features. This would mean that the use of jpeg compression has no effect, and could even make the new encoding less efficient (e.g. due to more noise). See also
opened 02:31AM - 23 Oct 24 UTC
feature request
pdf
### Description
JPG images can get included without reencoding the image when… exporting to PDF.
We can see this with the following latex code and [this](https://polona.pl/item-view/dac0ab7a-43b6-48e5-8492-a38e0b744cde?page=0) file (filesize=8.4 mb):
```latex
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=4cm]{map.jpg}
\end{document}
```
The resulting PDF compiles fast and has filesize 8.41 mb.
With typst, it seems the JPG is decoded and then reencoded, which is slower and makes the filesize bigger:
```typst
#image(width: 4cm, "map.jpg")
```
The resulting PDF has filesize 9.29 mb.
Note: for PNG also a [variant](https://tex.stackexchange.com/questions/39929/fast-png-embedding-using-pdflatex) exists that can get copied into the document without reencoding.
### Use Case
When exporting to PDF and having JPG images included:
- smaller binary size
- faster compilation times
- probably better image quality (original is kept)