How to screenshot only part of the canvas with RenderTargetTexture

Hello guys,
Let’s say I have a box with a certain width and height (which is not constant,dimensions might change) and I need to take a screenshot of it zoomed in as much as possible while fitting the whole box in the screenshot and keeping aspect ratio? Camera needs to be orthographic. I can make the box fit in the screenshot but I get a lot of dead space to keep the canvas ratio and it doesn’t look good.

Hmmm I don’t think there is a way besides “cropping” your screenshots in another pass :confused:

How can I crop my screenshots via code? Any suggestions?

I think the easiest method would be with drawImage on canvas: CanvasRenderingContext2D.drawImage() - Web APIs | MDN (mozilla.org)

Thank you @carolhmj. I actually ended up resizing the canvas according to my preferences and calculating the ortho values for my orthographic camera while taking the screenshots. I reset the size after I was done with the screenshots. It worked for me and it wasn’t too much trouble to implement.

Glad to know you found a solution!