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

Exported Mermaid graphs as PNG are incredibly small #7521

Closed
Tracked by #7629
iRomanyshyn opened this issue Dec 22, 2022 · 4 comments · Fixed by #7546
Closed
Tracked by #7629

Exported Mermaid graphs as PNG are incredibly small #7521

iRomanyshyn opened this issue Dec 22, 2022 · 4 comments · Fixed by #7546
Labels
bug It's a bug desktop All desktop platforms high High priority issues

Comments

@iRomanyshyn
Copy link

I don't know when it started. Maybe, a couple of weeks ago. Joplin on Ubuntu started making Mermaid renders very small in size if I export them as PNG.

Environment

Joplin version: 2.9.17
Platform: Ubuntu 22.04

Steps to reproduce

  1. Paste the code:
flowchart TD;

b ===> a
b === c
c -...- |Test| b
d & e & f --- b

subgraph "A"
	a
	d
	e
	f
	b
end
Loading
flowchart TD;

b ===> a
b === c
c -...- |Test| b
d & e & f --- b

subgraph "A"
	a
	d
	e
	f
	b
end
  1. Click the right mouse button on the rendered image and save it somewhere as PNG.
  2. Check the PNG file size. It will be 4.5kB which is catastrophically small to distinguish anything from there.

Describe what you expected to happen

Expected to have a bigger image than this.
mermaid-1671722589364

@iRomanyshyn iRomanyshyn added the bug It's a bug label Dec 22, 2022
@laurent22 laurent22 added desktop All desktop platforms high High priority issues labels Dec 23, 2022
@tessus
Copy link
Collaborator

tessus commented Dec 23, 2022

One more thing for me to add to my Mermaid tests: exporting to png/svg.

I am sorry that I missed this. I totally forgot about this feature.

Update: Although I doubt it's Mermaid, b/c exporting to PNG is not done with Mermaid.

@adarsh-sgh
Copy link
Contributor

Save as png option converts svg code of the image into png and saves it.

Svg Images have a viewBox attribute, we can use it to define width and height of the image we will be saving as png.
e.g. the mermaid in first comment of this diagram has svg:

<svg viewBox="-8 -8 258.080078125 446" ...

so setting png dimensions to 258 * 446 we get following png image
afterChange

Should I open A PR with these changes ?

@tessus
Copy link
Collaborator

tessus commented Dec 26, 2022

Yes, I think that would make sense. Please do.

P.S.: If the origin point is negative, doesn't it mean we should add those values ABS(x, y) numbers to x' and y'.

e.g. for this image 266x454

@adarsh-sgh
Copy link
Contributor

If the origin point is negative, doesn't it mean we should add those values ABS(x, y) numbers to x' and y'.

I think the size of image would remain same regardless of origin changes so we need not add it to width and height.
following image has first two parameter of viewBox as -50 but still it has same dimensions as original image.

image

viewBox is drawn with red

@tessus tessus changed the title Now, it makes incredibly small Mermaid graphs... Exported Mermaid graphs as PNG are incredibly small Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It's a bug desktop All desktop platforms high High priority issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants