Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH 1151: export GIF #1200

Merged
merged 13 commits into from
Apr 17, 2023
Merged

GH 1151: export GIF #1200

merged 13 commits into from
Apr 17, 2023

Conversation

ejulio-ts
Copy link
Contributor

@ejulio-ts ejulio-ts commented Apr 14, 2023

Fixes #1151

This allows diagrams to be exported as animated GIFs.

There is a minor refactor to introduce exportExtension in order to avoid having many file extensions around the code. It is the first commit and then further commits have minor changes to the initial idea.

The overall export piece needs some refactoring, as the PNG code is duplicated in all formats (pptx, png, pdf, gif). Similarly, the sequence in which we export multiple boards. As it seemed a bigger change, I left it out for now and may revisit it later.

The basic idea is:

  • Export all boards as PNGs
  • Convert PNGs to Bitmaps (GIF frames) with 255 colors (this is the reason I had to add a new library)
  • Make all GIF frames the same size (largest width and height of all boards)
  • Center the diagrams in the frame and keep a white background
  • Export the animation with an infinite loop

Note that this can "slow" as there are many image manipulations going on and it depends on the image size. I considered using goroutines here, but left out for simplicity at first. The examples below took between 5s-8s to compile.

8s
animated

5s
animated-2

@ejulio-ts ejulio-ts requested a review from gavin-ts April 14, 2023 18:55
Copy link
Collaborator

@alixander alixander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing that it works, hell yeah.

Can you add a periodic message that it's still running?
https://github.com/ejulio-ts/d2/blob/d1bb3cc575a9f6f1bc5d00067ff8e39a61a2e5de/lib/png/png.go#L93

@ejulio-ts ejulio-ts requested a review from alixander April 14, 2023 22:52
@ejulio-ts ejulio-ts requested a review from alixander April 17, 2023 13:43
@ejulio-ts ejulio-ts requested a review from alixander April 17, 2023 17:09
@ejulio-ts ejulio-ts merged commit ac1ea5f into terrastruct:master Apr 17, 2023
@ejulio-ts ejulio-ts deleted the gh-1151-gif branch April 17, 2023 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gif export
3 participants