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

Images not showing up when exporting to SVG or PNG on play.d2lang. #1985

Closed
tcaky opened this issue Jun 24, 2024 · 7 comments
Closed

Images not showing up when exporting to SVG or PNG on play.d2lang. #1985

tcaky opened this issue Jun 24, 2024 · 7 comments

Comments

@tcaky
Copy link

tcaky commented Jun 24, 2024

Edit: I am on Windows, using Firefox if it makes a difference for the issue.

Simple sequence diagram:

vars: {
  d2-config: {
    layout-engine: elk
    # Terminal theme code
    theme-id: 300
  }
}

push_model: Push Model {
  shape: sequence_diagram
  github: "GitHub Action" {
    shape: image
    icon: https://icons.terrastruct.com/dev%2Fgithub.svg
  }
  gcp_artifact_registry: "Artifact Registry" {
    shape: image
    icon: https://raw.githubusercontent.com/tcaky/WikiMeThis/main/media/google-cloud-icons/artifact_registry/artifact_registry.svg
  }
  gcp_cloud_run: "Cloud Run" {
    shape: image
    icon: https://icons.terrastruct.com/gcp%2FProducts%20and%20services%2FCompute%2FCloud%20Run.svg
  }
  # github."Credentials stored in GitHub for use by actions to push to GCP"
  github -> github: Detect change to\nbranch being monitored
  github -> github: Build container
  github -> gcp_artifact_registry: Update image in registry
  github -> gcp_cloud_run: Push new image
}

When I export the above, the images are not being added to either the PNG or SVG outputs.
simple-push-model
simple-push-model

@tcaky tcaky changed the title Images not showing up when exporting to SVG or PNG on d2lang. Images not showing up when exporting to SVG or PNG on play.d2lang. Jun 24, 2024
@bo-ku-ra
Copy link
Contributor

bo-ku-ra commented Jun 25, 2024

on windows, svg export is fine but png has no icons. #1983 (comment)

@hookor
Copy link

hookor commented Jun 28, 2024

Facing the same issue, I'm using chromeOS, Chrome. I tried unify image format with svg as I was using both png and svg but still didn't work.

@lovette
Copy link

lovette commented Aug 27, 2024

I've had this issue for years and every now and then I spend a few hours trying to find a solution. Chrome doesn't even make a request for the icons referenced in my exported .svg 🤨 Today, thinking it could be related to CORS somehow, I downloaded the .svg for all the icons so there are no cross-site requests. No matter what I try, the icons are visible on the playground but not when I open a page that references the exported .svg. It's the same result whether served locally (via mkdocs) or through Cloudflare Pages.

@bo-ku-ra
Copy link
Contributor

bo-ku-ra commented Aug 27, 2024

i tried it on windows edge, now.
no problem.
is chrome's security policy cased? (CORS?)

@lovette
Copy link

lovette commented Aug 28, 2024

I forgot to mention, that I have the same problem in Safari. Late last night it occurred to me that I hadn't tried opening the .svg directly. That worked! All the icons are shown.

The solution is to change this (which mkdocs generates):

<img src="/images/pods.svg" />

To this:

<object type="image/svg+xml" data="/images/pods.svg"></object>

If only I had thought of this two years ago 🙄

@bo-ku-ra as you mention above, my icons do not appear in the exported .png either, but I suspect that's an issue on the Playground backend.

@bo-ku-ra
Copy link
Contributor

bo-ku-ra commented Aug 28, 2024

"<object>" uses the svg's own path. (ex. pods.svg)
"<img>" uses the path of the caller's file. (ex. index.html)
i think that d2 should use "<object>".

root/
  ├ index.html
  └ svg/
     ├ pods.svg
     └ images/
        └ foobar.png

pods.svg (the caller is index.html)

<img src="svg/images/foobar.png"/> is correct.
<object type="image/svg+xml" data="/images/foobar.png"></object> is correct.

@alixander
Copy link
Collaborator

alixander commented Sep 4, 2024

fixed by fetching and encoding the images to base64 through proxy

png export:
d2 (16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

5 participants