Jude Law probably knew what he was getting into. After all, the writer and director of his new film was Richard Shepard.

Shepard’s previous effort, 2005’s larky comic thriller “The Matador” torpedoed Pierce Brosnan’s suave image by having him march drunkenly through a crowded hotel lobby wearing only a Speedo and cowboy boots.

Still, Law’s introductory scene in Shepard’s crime comedy “Dom Hemingway,” is one for the books. Naked, sweaty, sporting a beer paunch and mutton chop sideburns borrowed from Robert Shaw in “Jaws,” Law faces the camera and delivers a lengthy, profane soliloquy about the magnificence of his manhood.

Putting his stars in embarrassing situations delights Shepard. “There’s nothing funnier than the sight of a man of a certain age wearing not very much,” he said in a phone conversation from Los Angeles. “As a man of a certain age myself, I know that all too well.”

In “Dom Hemingway,” which opens Friday in the Twin Cities, Law plays the title character, a loudmouthed safecracker emerging from prison after a dozen years, eager to pick up the hush money he earned by keeping mum about his accomplices and get on with his life. He’s a gone-to-seed Cockney hooligan and a bit of a fool. Shepard suspected that after a decade of playing romantic roles and his recent run as the good and proper straight man Dr. Watson to Robert Downey’s Sherlock Holmes, Law would jump at an the chance to play a debauched, porky ex-con. And jump he did.

“We had a blast making the movie together. He was attracted to the theatricality of it and also the mess that Dom was — the bloated alcoholic overweight mess that Dom is,” Shepard said. “The timing was right for Jude in his career. He had a long stretch playing leading men and he’s segueing now into a second stage where he’s ultimately a character actor.”

Law last year made a dramatic move in that direction, downplaying his charismatic good looks to play the cold, pious spurned husband in “Anna Karenina.” He had earlier played against his pretty boy image as a ghoulish Chicago assassin in the Tom Hanks gangster tale “Road to Perdition.” “Dom Hemingway” enabled him to stretch his wings in a full-fledged leading role.

“In casting, when you don’t have tons of money, you seek out an actor you think might be up for something different.” Shepard said. That goes for the rest of the eccentric ensemble he pulled together.

Demian Bichir (of TV’s “Weeds”) plays Dom’s dandyish boss Mr. Fontaine. The Mexican star accepted the role on the condition that he could play Fontaine as a Russian. Romanian fashion model Madalina Ghenea makes her English-language acting debut as the crime boss’s shifty Italian mistress. Richard E. Grant plays Dom’s dry-as-toast sidekick, who has a wooden hand, for reasons never discussed. And raven-haired Emilia Clarke (of “Game of Thrones”) plays Dom’s long-lost daughter.

To get out of shape for the film, Law “ate a lot of fish and chips, and drank a lot of beer,” Shepard said. “We even had his suits made extra tight so he would be bulging from them. The tailor nearly had a heart attack, seriously.”

The extra weight lends a sense of truthfulness to a scene where the fabled safecracker attacks an uncooperative lockbox with a sledgehammer. Law, who had been smoking heavily as part of his preparation, was panting like a distance runner at the end of each take.

“When you’re seeing something really special, an actor is lost in his character,” Shepard said. “Whether it was the yellow teeth we put on him, the facial hair, the receding hairline, he was able to create Dom.”

Dom is a radically unlikable character. Early on we see him beat the man who had been living with his wife while he was in prison. Then we learn that the fellow took care of her throughout her death from cancer. Still, the film’s humor makes him a (barely) sympathetic rogue.

“He uses his mouth as a weapon and shoots himself in the foot a lot with it,” Shepard said. Even in the florid, foulmouthed opening scene, Shepard was aiming for “some weird gutter poetry that makes it not just an assault. Something sort of enjoyable about the language even as it is shocking. When you see him being so physically and verbally violent, part of the fun of the movie is getting nervous that he’s not going to screw things up for himself again. The tension of the movie is rooting for a guy that it doesn’t make a great deal of sense to be rooting for. That’s why I was so grateful to have Jude law reading my dialogue. He made it sound so much better than it looked on the page.”