Fact 1. in the book lord of the rings Gimli is presented as a well-spoken, intelligent and extremely dignified dwarf. Legolas, meanwhile, is depicted as loveable, but somewhat frivolous, rude and annoying.
Fact. 2 in the film lord of the rings Legolas is a presented as a dignified, hyper-focused warrior, basically the world’s best archer, and capable of pulling of absurd feats of bravery and finesse. Gimli, meanwhile, is shown as loveable, but also brash, clumsy and basically a walking short joke.
Fact 3. in the appendices to return of the king it’s stated that Frodo’s biggest source of information for events the hobbits weren’t involved in was Gimli. Therefore a lot of what we see of Legolas is filtered through Gimli.
The Legolas, Aragorn and Gimli arc is being told from Gimli’s perspective and Legolas is presented accordingly. Book!Gimli is how Gimli sees himself and Book!Legolas is how Gimli sees Legolas.
Theory: in the films, the Legolas, Aragorn and Gimli arc is being told from Legolas’s perspective, hence the dramatic change in characterisation. Film!Legolas is how Legolas sees himself. Film!Gimli is how Legolas sees Gimli.
In the book, we’re seeing Legolas and Gimli as Gimli sees them; in the film, we are seeing Legolas and Gimli as Legolas sees them. The truth? Must lie somewhere in between.