Jude Law packed on 20 pounds to star as an ex-con in “Dom Hemingway,” and told The New York Post that he got used to overindulging.

“It was tough to turn it off at the end,” he admitted. “It was allowing myself to say ‘yes’ to everything — ice cream . . . burgers . . . all the wrong stuff.”

Director Richard Shepard said at the New York City premiere on Thursday that he appreciated Law’s commitment to the role but wanted to keep him alive.

“He was drinking, like, 10 sodas a day, drinking nonalcoholic beer, which is disgusting, and he was pasty-faced [from] smoking. I was like, ‘Just please don’t have a heart attack until we are done filming.’ ”