# Download the texture as image from texture Canvas

**URL:** <https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073>\
**Category:** Questions\
**Tags:** material\
**Created:** [January 25, 2022, 1:02pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073 "2022-01-25T13:02:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mostafa\_Salloum](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mostafa_salloum/32/13074_2.png) [@Mostafa\_Salloum](https://forum.babylonjs.com/u/Mostafa_Salloum)\
**Post date:** [January 25, 2022, 1:02pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/1 "2022-01-25T13:02:23Z")

</div>

Hello, I am trying to download the image of the texturecanvas texture.  
is there a way to do it ?

> **[Babylon.js Playground](https://playground.babylonjs.com/#436DIW%2323)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

this is a pg when you press on the mesh it will console the ctx but is there any function to get the texture (“no name”) in inspector at the textures section

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [January 25, 2022, 2:49pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/2 "2022-01-25T14:49:13Z")

</div>

Good morning @Mostafa_Salloum

I took a look at your PG and this is what I got:

Usually, you should be able to use the texture inspector by clicking on the texture in the asset list like so.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/b/1b086d0d8390f007ac90c6f7a9483077f5b9db4f.png)

However, when I clicked on the no-name textures the inspector closed. Is this because they are null? Is this a bug? Since you mentioned downloading I tried downloading the entire project using this button.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/4/e4255c48f0579d1eb58c6542624b2c8e338ec46f.png)

This usually has a textures folder inside it, but in this case, it was empty.

---

<div class="post-metadata">

**Author:** ![Mostafa\_Salloum](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mostafa_salloum/32/13074_2.png) [@Mostafa\_Salloum](https://forum.babylonjs.com/u/Mostafa_Salloum)\
**Post date:** [January 25, 2022, 3:07pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/3 "2022-01-25T15:07:18Z")

</div>

Yes 100% the no name is there and i can inspect it and even download it when in the edit section of textures make sure you are using version 4.2 not 5.0 to see it  
So the texture is there but its value is null and url is null and buffer is null its so i cant convert it from texture to an image  
I am asking of there are a way to make an image and add to it this texture (texturecanvas) and download it  
Thank you

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [January 25, 2022, 8:16pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/4 "2022-01-25T20:16:16Z")

</div>

Ah yes, I was running 5.0, I see it working now in 4.2

Ok! To clarify if I think I understand correctly we want to add in another image the already populated texture and then download it? The downloading should still be able to be done with the texture inspector.

Looking inside the code from there I found the following saveTexture function:  
Can take a look at our source code directly textureCanvasManager.ts

```auto
    public saveTexture() {
        const canvas = this._editing3D ? this._3DCanvas : this._2DCanvas;
        Tools.ToBlob(canvas, (blob) => {
            Tools.Download(blob!, this._originalTexture.name);
        });
    }

```

As far as adding an image onto the texture you should be able to create a dynamic texture with a given image like in this demo [https://playground.babylonjs.com/#5ZCGRM#4](https://playground.babylonjs.com/#5ZCGRM#4) and then add it to your canvasTexture.

Also going to put doc links for reference to anyone else:

> **[Dynamic Textures | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/materials/using/dynamicTexture)**
>
> Learn all about dynamic textures in Babylon.js.

> **[Texture Canvas | Babylon.js Documentation](https://doc.babylonjs.com/extensions/textureCanvas)**
>
> Learn about the texture canvas extension that functions as a texture that other textures can be drawn upon.

---

<div class="post-metadata">

**Author:** ![Mostafa\_Salloum](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mostafa_salloum/32/13074_2.png) [@Mostafa\_Salloum](https://forum.babylonjs.com/u/Mostafa_Salloum)\
**Post date:** [January 25, 2022, 11:37pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/5 "2022-01-25T23:37:34Z")

</div>

Thank you msDestiny for your answer, is there are an example or pg how i can use savetexture function?  
like i said i want to download the texture from the code without opening the inspector.  
and yes you got it i want to add an image or text to a texture that is already in the scene on a mesh  
so i am using texture canvas so is there a way download the texture canvas as image after i finish the adding proccess on the texture

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [January 27, 2022, 4:48pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/6 "2022-01-27T16:48:58Z")

</div>

Hey @Mostafa_Salloum

Here we go: [https://playground.babylonjs.com/#436DIW#34](https://playground.babylonjs.com/#436DIW#34)

In this example, I have it so when we click on the mesh the no named texture will print. I ended up using the code from the save texture function I posted above. The texture had to be converted to a canvas element using the following code (line 60-70)

```auto
var te = scene.textures.filter(text => text.name == "")[0];
console.log(te);

var data = await te.readPixels(0, 0);
var size = te.getSize();
var canvas2 = document.createElement("canvas");
var context = canvas2.getContext('2d');
var imgData = context.createImageData(size.width, size.height);
imgData.data.set(data);
context.putImageData(imgData, 0, 0);
document.body.appendChild(canvas2);

```

One thing that I’m slightly off-putted by is the size of the printed image. Feel free to play with it if you want to adjust. But now we have the printing step. 🙂

---

<div class="post-metadata">

**Author:** ![Mostafa\_Salloum](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mostafa_salloum/32/13074_2.png) [@Mostafa\_Salloum](https://forum.babylonjs.com/u/Mostafa_Salloum)\
**Post date:** [January 27, 2022, 6:36pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/7 "2022-01-27T18:36:31Z")

</div>

Thank you very much for your work i really appreciate what you did  
and yeah the size of the outputted image is very small just a question is there is a way where i can adjust the size the resolution ?

---

<div class="post-metadata">

**Author:** ![Mostafa\_Salloum](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mostafa_salloum/32/13074_2.png) [@Mostafa\_Salloum](https://forum.babylonjs.com/u/Mostafa_Salloum)\
**Post date:** [January 27, 2022, 8:05pm UTC](https://forum.babylonjs.com/t/download-the-texture-as-image-from-texture-canvas/27073/8 "2022-01-27T20:05:40Z")

</div>

nevermind i just changed  
context.canvas.height=512  
context.canvas.width=512

and now its downloading as full image  
Thanks
