Home > Blockchain >  How to include a chart in a mail
How to include a chart in a mail

Time:07-24

I send a daily report with table data to a number of subcribers. It would be nice to show the data in a chart or graph like a bar chart or a line chart. However, most graph libraries like GraphJS use javascript and javascript does not run in mails, at least not in Gmail.

Javascript does not run on my server.

I tried to generate the image server side and found goat1000's svggraph. It works, generates a nice svg, but unfortunately some mail clients like gmail do not display svg.

I'd like to avoid dependency on an external online svg to image converter.

Does anyone know a library to generate chart/graph images (gif, webp, png, ...) with native php or laravel? Or a php svg to image converter?

jpGraph is a possibility, but that is expensive for the small community project I target.

CodePudding user response:

You could probably use Browsershot

https://github.com/spatie/browsershot

This may take an html template and produce an image file which you can them embed or attach to the email.

CodePudding user response:

The non-standard ImageMagick php extension allows to convert many image formats, including svg.

It is as simple as:

$image = new \Imagick();
$image->readImageBlob($svg);
$image->setImageFormat('gif');
$gif = $image->getImageBlob();

On ubuntu, ImageMagick can be installed using sudo apt install php-imagick

SVG is disabled for security reasons in many installations. The list of supported formats can be seen in phpinfo()'s section ImageMagick supported formats. If SVG is missing, it can be enabled using sudo apt install libmagickcore-6.q16-6-extra

On my shared webserver, imagick is available with SVG support (Combell hosting).

  • Related