0

I am trying to convert an SVG to a PNG file in PHP. In my SVG, there is some text written that is lost during my convertion process. I use Imagick for that purpose and would rather stay on that solution, but as long as it is free, i am open to alternate libraries. My code is very simple :

    $i = new Imagick($svg);
    $i->setImageFormat('png');
    $image = $i->getImageBlob();

And the result :

glorious-cat.png

I assume it's something like the text fonts that are missing from Imagick during the process, especially since there is a setFont() method in the Imagick object. Unfortunately, I can't find where my font files are located in my alpine container.

What could I do in order to get my text to be properly displayed ?

Mouke
  • 854
  • 1
  • 7
  • 19
  • 1
    Alpine-based images are usually very lean and might not have _any_ installed fonts. Perhaps [this answer where the author installs `msttcorefonts`](https://stackoverflow.com/a/52762436) helps? – RickN May 10 '23 at 14:03
  • If you could convert that comment into an answer, so that I can check it. I didn't even think about the idea of not having any font at all. – Mouke May 10 '23 at 14:22
  • 1
    Feel free to write up an answer how you fixed it, I'm sure you can write up something more helpful than me just dropping a link. :-) You'll be able to [accept your own answer in 48 hour's time](https://stackoverflow.com/help/self-answer). – RickN May 10 '23 at 14:50
  • Sure, I just wanted to let you get the credit :) – Mouke May 10 '23 at 21:10

1 Answers1

1

So, thanks to RickN's comment, I managed to fix it.

Quite litterally I just used the very commmand in their link :

RUN apk --no-cache add msttcorefonts-installer fontconfig && \
update-ms-fonts && \
fc-cache -f

It's really all I needed to do.

Mouke
  • 854
  • 1
  • 7
  • 19