# How can I force a texture to fit a Plane without change it ratio

**URL:** <https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023>\
**Category:** Questions\
**Tags:** textures\
**Created:** [November 26, 2020, 1:48pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023 "2020-11-26T13:48:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aureliennezzar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aureliennezzar/32/14792_2.png) [@aureliennezzar](https://discourse.threejs.org/u/aureliennezzar)\
**Post date:** [November 26, 2020, 1:48pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023/1 "2020-11-26T13:48:18Z")

</div>

Hello 😃,

Its been few days I tried to search an answer to this but cant figured out how to do it, I hope I can find help here ^^

I’m using the “GooeyEffect” in this tutorial : [Making Gooey Image Hover Effects with Three.js | Codrops](https://tympanus.net/codrops/2019/10/23/making-gooey-image-hover-effects-with-three-js/)

I’m trying to make the texture image fit a plane in three.js while keeping the ratio of it in case of page resize.  
My problem is that the image fit the Plane

 ![bugEffect](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/f/f811a66ea87fa40bcc174842670b9ee847ddf114.jpeg) .

What I want is to “reproduce” the object-fit: cover behavior of css in three.js 🙂  
So the image fit the height of the plane and the width “exceeds” outside of it

Wanted effect :

 ![wantedEffect](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/8/8eb556f5d7f5e5cd53b60dc0e8e6189c63ab68dd.jpeg)

As you can see I have three Planes side by side in one single canvas. I am using a PerspectiveCamera if that can help in anyway 🙂

I hope I’m clear about what I want, sorry for my bad english btw 😅  
Thanks you in advance!

Cheers.

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [November 26, 2020, 2:06pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023/2 "2020-11-26T14:06:31Z")

</div>

Hi!  
Have a look at this forum topic: [Centered background texture](https://discourse.threejs.org/t/centered-background-texture/13079)  
You need to know ratios of width and height of an image, and width and height of a plane.

---

<div class="post-metadata">

**Author:** ![aureliennezzar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aureliennezzar/32/14792_2.png) [@aureliennezzar](https://discourse.threejs.org/u/aureliennezzar)\
**Post date:** [November 26, 2020, 4:14pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023/3 "2020-11-26T16:14:18Z")

</div>

Hey!  
I will try this thanks you very much.

---

<div class="post-metadata">

**Author:** ![drcmda](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@drcmda](https://discourse.threejs.org/u/drcmda)\
**Post date:** [November 26, 2020, 4:50pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023/4 "2020-11-26T16:50:59Z")

</div>

drei’s useAspect which is a css cover implementation [https://github.com/pmndrs/drei#useaspect](https://github.com/pmndrs/drei#useaspect) it’s just a small function, you could copy the code and adapt it. It doesn’t touch the textures but scales the mesh so that it fills the screen.

---

<div class="post-metadata">

**Author:** ![aureliennezzar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aureliennezzar/32/14792_2.png) [@aureliennezzar](https://discourse.threejs.org/u/aureliennezzar)\
**Post date:** [November 26, 2020, 5:31pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023/6 "2020-11-26T17:31:55Z")

</div>

I cant make it work, maybe because im using the texture as uniform in my vertexFragment ? I got some results but none of them are doing what I want…  
Here my code :  
Tile : [tile :: Sharemycode](http://sharemycode.fr/tile)  
Scene : [scene :: Sharemycode](http://sharemycode.fr/scene)

I’m quite lost, sorry im still a beginner 🙂

---

<div class="post-metadata">

**Author:** ![aureliennezzar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aureliennezzar/32/14792_2.png) [@aureliennezzar](https://discourse.threejs.org/u/aureliennezzar)\
**Post date:** [November 26, 2020, 8:56pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023/7 "2020-11-26T20:56:02Z")

</div>

This is it, I figured out, thanks to @drcmda’s answer  
Thanks guys for your replies 🙂

---

<div class="post-metadata">

**Author:** ![madleo](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@madleo](https://discourse.threejs.org/u/madleo)\
**Post date:** [July 8, 2021, 10:51pm UTC](https://discourse.threejs.org/t/how-can-i-force-a-texture-to-fit-a-plane-without-change-it-ratio/21023/8 "2021-07-08T22:51:08Z")

</div>

Care to share? I’m trying to work out drcmda’s code but cant seem to get it right…
