Spaces:
Runtime error
Runtime error
Download scripts/canvas.js from im1111/gemini-3d-drawing: direct link, hf CLI and curl.
- Browser
- Download file 797 Bytes
-
https://huggingface.co/spaces/im1111/gemini-3d-drawing/resolve/main/scripts/canvas.js
- Command line
-
hf download hf://spaces/im1111/gemini-3d-drawing/scripts/canvas.js
-
curl -L -o canvas.js https://huggingface.co/spaces/im1111/gemini-3d-drawing/resolve/main/scripts/canvas.js
797 Bytes
| function drawImageMaintainAspectRatio(ctx, image, canvas) { | |
| // Clear the canvas first | |
| ctx.fillStyle = '#000'; // or '#fff' for white bars | |
| ctx.fillRect(0, 0, canvas.width, canvas.height); | |
| // Calculate aspect ratios | |
| const imageRatio = image.width / image.height; | |
| const canvasRatio = canvas.width / canvas.height; | |
| let drawWidth, drawHeight, x, y; | |
| if (imageRatio > canvasRatio) { | |
| // Image is wider than canvas | |
| drawWidth = canvas.width; | |
| drawHeight = canvas.width / imageRatio; | |
| x = 0; | |
| y = (canvas.height - drawHeight) / 2; | |
| } else { | |
| // Image is taller than canvas | |
| drawHeight = canvas.height; | |
| drawWidth = canvas.height * imageRatio; | |
| x = (canvas.width - drawWidth) / 2; | |
| y = 0; | |
| } | |
| ctx.drawImage(image, x, y, drawWidth, drawHeight); | |
| } |