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

Why image is not show #515

Open
abhisunny2610 opened this issue Jan 9, 2025 · 0 comments
Open

Why image is not show #515

abhisunny2610 opened this issue Jan 9, 2025 · 0 comments

Comments

@abhisunny2610
Copy link

export function setupCanvas(graph, backgroundImageUrl) {
const canvas = new LGraphCanvas("#graph-canvas", graph);

// Load background image if provided
if (backgroundImageUrl) {
const img = new Image();
img.src = backgroundImageUrl;
console.log("Loading image from:", img.src);

img.onload = () => {
  console.log("Image loaded successfully:", img.src);

  // Manually draw the background image
  const ctx = canvas.canvas.getContext("2d");
  ctx.drawImage(img, 0, 0, canvas.canvas.width, canvas.canvas.height);

  console.log("Background image drawn manually");
};

img.onerror = () => {
  console.error("Failed to load background image:", img.src);
};

}

// Zoom Controls
document.getElementById("zoom-in").onclick = () => {
if (canvas.ds.scale < 2) {
// Limit max zoom
canvas.ds.scale *= 1.2;
canvas.setDirty(true, true);
}
};

document.getElementById("zoom-out").onclick = () => {
if (canvas.ds.scale > 0.2) {
// Limit min zoom
canvas.ds.scale *= 0.8;
canvas.setDirty(true, true);
}
};

/**

  • Resizes the canvas to fit its container
    */
    function resizeCanvas() {
    const canvasElement = document.getElementById("graph-canvas");
    const container = document.getElementById("graph-container");
    canvasElement.width = container.offsetWidth;
    canvasElement.height = container.offsetHeight;
    canvas.setDirty(true, true);
    }

// Handle window resizing
window.addEventListener("resize", resizeCanvas);
resizeCanvas();

return canvas;
}

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

No branches or pull requests

1 participant