简体   繁体   English

从链接获取 canvas 作为图像

[英]Get canvas as an image from link

I have a p5.js canvas on my webpage, I want to get that canvas as an image from the link, just like a raw media file being hosted on a website, such that I can use it as just a normal get media link, not sure what the technical term is.我的网页上有一个 p5.js canvas,我想从链接中获取 canvas 作为图像,就像托管在网站上的原始媒体文件一样,这样我就可以将它用作普通的获取媒体链接,不确定技术术语是什么。

Is this possible, or will I have to download the image locally first and just use it from the drive?这可能吗,还是我必须先在本地下载图像并从驱动器中使用它?

I don't know of a way to do this, but you have some options.我不知道如何做到这一点,但你有一些选择。

Option 1: embed your sketch as a canvas element, which is what p5.js is designed to do.选项 1:将您的草图嵌入为canvas元素,这是 p5.js 的设计目的。 My gut tells me that this is probably what you should really do.我的直觉告诉我,这可能是你真正应该做的。

Option 2: save your sketch (or several versions of your sketch) as an image by right-clicking it, and then serve that as a normal image.选项 2:通过右键单击将草图(或草图的多个版本)保存为图像,然后将其用作普通图像。

Option 3: do some kind of server-side rendering of a p5.js canvas, and serve that as an image.选项 3:对 p5.js canvas 进行某种服务器端渲染,并将其作为图像提供。 This is pretty advanced, but you can google "p5.js server side" for more info.这是相当先进的,但你可以谷歌“p5.js 服务器端”了解更多信息。 My gut tells me that this is probably not what you should really do.我的直觉告诉我,这可能不是你真正应该做的。

Honestly it sounds like you're trying to use p5.js for something it wasn't meant for.老实说,这听起来像是您试图将 p5.js 用于它不适合的东西。 Most places you can embed an image, you can embed a p5.js canvas, so my guess is that you probably want to do that instead.大多数地方你可以嵌入图像,你可以嵌入 p5.js canvas,所以我猜你可能想要这样做。 But server-side rendering is the direction I would explore if you're super curious.但是如果你超级好奇的话,服务器端渲染是我会探索的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM