lovell / lovell/sharp

SVG: support for CSS calc()

Open
#3,055 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

blocked-upstream-dependency enhancement
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

Hello, I want to output a line graph SVG to a png using Sharp. The axis and legends are on top of the padding space of the SVG as overflow, shown in the picture below.

![graph1](https://user-images.githubusercontent.com/71924703/150712429-335871d5-eaf0-4fe8-8d4c-cae68df7351b.PNG)

But it seems the padding area does not get included into the output png file.

![output](https://user-images.githubusercontent.com/71924703/150712872-6ec6b1c0-5e8c-4c2a-8349-1e0cfa92d439.png)

I used the following code to create the output:
```
const element = renderToString(svg);
sharp(Buffer.from(element))
.png()
.toFile("output.png", Object);
```

Here is also a JSFiddle with the SVG:
https://jsfiddle.net/Lefsqo3j/14/

Is there a way for the padding area to be captured in the output png together with the graph?
Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SVG from the linked JSFiddle and the sharp(Buffer.from(element)) conversion entry point; investigate how CSS calc() and overflow/padding are handled during SVG-to-PNG rendering. Done means the padding area shown in the SVG is included in the generated PNG, with coverage for the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.