英文:
How to convert an SVG into PNG in PHP without losing written text
问题
我正在尝试将SVG转换为PHP中的PNG文件。在我的SVG中,有一些文本在转换过程中丢失了。我用Imagick来实现这个目的,宁愿坚持这个解决方案,但只要是免费的,我也可以考虑替代库。
我的代码非常简单:
$i = new Imagick($svg);
$i->setImageFormat('png');
$image = $i->getImageBlob();
结果:
我猜这可能是在Imagick过程中缺少的文本字体之类的东西,特别是因为在Imagick对象中有一个setFont()方法。不幸的是,我找不到我的字体文件在我的alpine容器中的位置。
为了正确显示我的文本,我该怎么做?
英文:
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 :
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 ?
答案1
得分: 1
感谢RickN的评论,我成功修复了它。
实际上,我只是使用了他们链接中的这个命令:
RUN apk --no-cache add msttcorefonts-installer fontconfig && \
update-ms-fonts && \
fc-cache -f
这确实是我需要做的一切。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论