It’s a high-class but increasingly common problem: being a former magazine editor in a digitized world that cares little about whose name used to be on top of a defunct masthead. (A masthead, for those unfamiliar with the term, lists in careful hierarchy the top staff of a publication and is most often printed on paper — which tells you pretty much all you need to know.)

At 48, Dan Peres is already an old hand at being a former magazine editor. Condé Nast shut down Details, the men’s glossy that he had been editor of for 15 years, in 2015. Overnight Mr. Peres went from two decades spent as a coveted presence at fashion shows and parties in the world’s capitals to a divorced dad adrift in the ’burbs.

He tried to pivot to digital publications, but quickly learned there is little job security in start-ups. He took on some consulting gigs. He was also jotting down stories from his past life, one not many people knew about.

“I started to have some conversations about next steps career-wise, and during that time I started writing,” Mr. Peres said last week, sitting in his home office in Irvington, N.Y., at a wooden drafting desk that he had lugged from Paris. “There were experiences I wanted to get down on paper. I wanted to keep my mind sharp.”

The result is a memoir, “As Needed for Pain,” which was published this week by Harper, an imprint of HarperCollins.

Credit…Sara Krulwich/The New York Times

In the book, Mr. Peres reveals an opioid addiction that he tried for years to hide, and which, until he got clean in 2007, had him taking as many as 60 Vicodin pills a day. Among many anecdotes that illustrate his wincing desperation, he tells of gobbling up pills that had fallen onto the floor beneath a urinal at a black-tie event in 2003. “Does the five-second rule count for piss-soaked drugs?” Mr. Peres writes. “I’d like to say I hesitated.”

“You can’t fault his honesty, although you’ve got to wonder about the judgment of his bosses,» Jay McInerney wrote in a review for The New York Times. And indeed, “As Needed for Pain” is an eye-opening document of how Mr. Peres for seven years spent his working hours and many of his company’s dollars in pursuit of getting high.

Since 2009, Condé Nast has gone from publishing 22 magazine brands (including one digital-only publication) to 16 magazine brands (six of which are digital only). In 2017, the company had about $120 million in losses.

Mr. Peres’s reign seems to have epitomized the bloated pride before the fall. Founded by Annie Flanders as a scrappy downtown magazine in 1982, Details had gone through several iterations before being taken over by Fairchild, which was ultimately moved under the Condé Nast umbrella. With Mr. Peres as editor, the magazine was retooled as a manual for a metrosexual clinging to a certain frat boy quality, lest you call him gay.

Details had for a time what Tina Brown always used to call “buzz,” with cover models like Robert Downey Jr., Kevin Federline (twice!) and Ben Affleck. It was not so filled with ads that it was a doorstop, like the flagship magazines Vogue and Vanity Fair, but it was still robust.

Freelance journalists wanted to contribute to Details (I was one, reporting a profile of Patrick Kennedy for it in 2001), and the magazine won awards for its design.

Condé Nast, which also then regularly published the magazines Gourmet, Jane, Lucky and Domino, had become famous through shows like HBO’s “Sex and the City.” The company was known for around-the-block Town Cars filled with enigmatic editors who lunched at New York restaurants like the Four Seasons and enjoyed clothing expense accounts and interest-free mortgages provided by their employer.

After being summoned at 28 from Paris where he had worked as a writer and editor for W magazine and given the top job at Details, Mr. Peres lived subsidized for months in the Morgans Hotel. Once, he trashed his room because he couldn’t find his Vicodin; he blamed the housekeeper for stealing his drugs.

The hotel staff “called me Mr. Peres,” he writes. “I liked it. I never once told them to call me Dan.”

Editors of glossy magazines had status then because their products seemed important. People went to newsstands or physical mailboxes to find bound pieces of paper dropped by postal workers that would tell them who and what was cool, giving them topics for cocktail-party and water-cooler chatter.

Portable phones were these whiz-bang things that folded shut and were tucked away in pockets and expensive “It” bags.

The early and mid-aughts were the Roaring ’20s of magazines, with the looming economic recession not yet imaginable and the disruption of digital media not considered by publishing executives, so infatuated with their pretty print pages and the huge margins that print advertising delivered. No matter that their one real job was to have their fingers on the pulse of What’s Next.

“Those that are the oracle never think they’re one day not going to be the oracle any longer,” said Ariel Foxman, who helped create Cargo magazine in 2003 for Condé Nast, which closed it in 2006.

Mr. Foxman went on to become editor in chief of InStyle, where he remained until 2016. He is currently trying to sell a memoir called “The Magnificent Dissolve,” which looks at how magazines “led the conversation and then found themselves in the course of a few years chasing the conversation and trying to stay relevant.”

If published, it will join a subgenre of memoirs by onetime Condé Nast editors that includes Ms. Brown’s “The Vanity Fair Diaries”; “Save Me the Plums,” by Ruth Reichl, the former New York Times restaurant critic who went on to become Gourmet’s editor until Condé Nast shuttered it in 2009; and “More Than Enough,” by Elaine Welteroth, late of Teen Vogue.

“What a blast to be a part of something at its peak that now can be seen as a golden age,” said another memoirist, Dana Brown. Mr. Brown was a bartender plucked for an assistant job by the former Vanity Fair editor Graydon Carter.

He rose to be one of Mr. Carter’s deputies and is now writing “Disappearing Ink,” the working title of a memoir about the experience. “It was a time that was pre-technology, it was a time that was magical,” he said. “Writers were called writers, photographers were called photographers. It was before we all became ‘content creators.’”

Kim France was the founding editor of Lucky magazine, which started in 2000 and ceased publishing in 2015. She too is writing a memoir: “This Is Not My Beautiful House,” about moving from Texas to New York and building an outwardly glamorous career while battling substance abuse and depression. (She left Condé Nast in 2010.)

Her mood swings and impetuous behavior were initially treated as a sign of her creative talent, Ms. France said. This was the Condé Nast way.

“It was a privately held company, and they could employ all these really creative, kind of crazy people,” she said. “You had André Leon Talley swanning around. There was drama all over the place. It was obviously bad that this culture existed the way it did, but it started because they valued creativity and the kind of people that were creative.” (As it happens, Mr. Talley also has a memoir set to publish, in April, called “The Chiffon Trenches.”)

It was a culture that somehow allowed Mr. Peres for seven years to live a dual life as an editor in chief responsible for the publication of a national magazine and the management of dozens of employees, and an opioid addict.

When writing the book, Mr. Peres said, it didn’t occur to him that he might be revealing a lack of corporate oversight at Condé Nast or what a white man could get away with doing (and not doing) at a company known for its lavish spending.

“I didn’t overthink it,” he said. “I always set out to write a story about myself and my addiction and how intense of a grip it had on me, and in order to illustrate that, I had to touch on a number of elements of my life, including of course my professional life. I really see Details as a character in the book.”

A spokesman for Condé Nast said, “We’re happy for Dan’s recovery and to know that he’s doing well. Since the time chronicled in Dan’s book, our company and our industry have evolved significantly, and we can’t comment on the way our company was run under prior leadership.”

Mr. Peres tells in his memoir of frequently not making it into the office; when he did, he sneaked occasional naps on his office couch during the heavy drug years. He fell asleep while interviewing a job applicant. He had an assistant plan an unnecessary trip to San Diego, where he rented a car (he doesn’t remember if he or the company paid for it), drove to Tijuana, Mexico, and bought $6,000 worth of drugs to smuggle back across the border and then to New York (in between, he appeared on “Politically Incorrect” with Bill Maher in Los Angeles).

He would find reasons to fly to Los Angeles, to meet a publicist, see his girlfriend, do drugs with a rock star, who is unnamed (“plane highs were usually the best, especially in first class,” Mr. Peres writes). That girlfriend, the actress Sarah Wynter, would become his wife and then ex-wife; they have three school-age sons.

He spent four days “in a plush terry cloth robe” at the Four Seasons in Milan without attending the fashion shows he had traveled there for because he didn’t have sufficient Vicodin to feel like himself. (He then had the front desk send a medico to his room, who wrote him a prescription.)

Mr. Peres conscripted an assistant to unwittingly create with the Condé Nast travel office a 30-day itinerary to Italy and Australia that he could show to doctors as evidence that he needed to fill prescriptions in advance.

On a work trip to Los Angeles, Mr. Peres considered trying heroin and asked his driver to take him to Skid Row, where he was chased by a stranger whom he’d asked for drugs (“It’s not easy to run for your life in a pair of Tod’s driving moccasins,” he writes). He decided buying drugs on the street was not for him.

“I listened to Journey and practically knew the room service menu at the Ritz in Paris by heart,” he writes. “I didn’t know how to do this.”

His Town Car driver in Los Angeles, he writes, became his drug dealer.

When he was present, Mr. Peres could be mercurial, some former colleagues said. “You never knew what kind of day it would be,” said Ece Ozturk, his former assistant, who worked at Details for about six years. “Would it be a good day with the nice Dan or a bad day with the mean Dan? He could be very charming at times, but people were afraid of Dan. People walked on eggshells around him.”

One former employee who had been fired sent a letter to Mary Berner, a publishing executive overseeing the company division that included Details. The letter, which was shared with The Times, cited “Dan Peres’s conspicuously frequent absences” and his “admissions about pill-taking.”

“The atmosphere at this young men’s magazine wasn’t just freewheeling — it was unprofessional,” the fired employee wrote.

Ms. Berner, now the C.E.O. of Cumulus Media, said she had no memory of reading the letter. “I wish I had known” about Mr. Peres’s drug problem, she said, “because I would have tried to help him.”

Mr. Peres writes that his assistant was known to many at Details as “the Rescheduler.” In one seven-week period Ms. Ozturk sent at least five emails to staff canceling meetings, according to emails reviewed by The Times. (“Dan is not in this morning, but may be in this afternoon” … “Dan will be out tomorrow, returning Friday” … “Dan is out today” … “Dan will be away on business tomorrow and Thursday, returning Friday.” Or maybe not: “Dan did not make it back from L.A. so to those who were supposed to have a ‘Vitals’ meeting,” she wrote, referring to a section of the magazine, “it has been canceled.”)

In the absence of a functional editor in chief, the staff of Details worked long hours to put out a magazine. “There were a lot of people there who could pick up the baton,” said Andrew Essex, an advertising executive who served for part of Mr. Peres’s tenure as executive editor.

Over the years, Mr. Peres’s colleagues included Laura Brown, now the editor in chief of InStyle; Jessica Lustig, a deputy editor of The New York Times Magazine; Jeff Gordinier, the food and drinks editor for Esquire; and Andrea Oliveri, a founder of the events company Special Projects.

Even with such support, Details under Mr. Peres had its fair share of mess-ups that these days, under the stern gaze of social media, might have been unsurvivable. In 2007, as Mr. Peres was trying to detox at his mother’s house in Baltimore, Mr. Affleck complained that he was misquoted in a cover story.

There was a party that the magazine was hosting in Mr. Affleck’s honor, and he needed to be placated. Mr. Peres quickly apologized.

Bart Blasengame, who had written the story, conceded that he had played fast and loose with Mr. Affleck’s sentences.

“He said things in fits and starts and I took quotes from different parts of the interview and made them cohesive,” said Mr. Blasengame, who now owns and runs a music club in Portland, Ore.

He said part of the fun of working for Details was the lack of oversight. “We were running the show,” he remembered of himself and his fellow writers. Then, after the publication of the Affleck story, which had been fact-checked and given the OK by Mr. Peres, his contract was terminated (though he went on to receive other assignments from Details). “Admittedly, I didn’t handle it well,” he said, “but it definitely felt like getting thrown under the bus.”

In 2002, the magazine had published an article, “Dudes Who Dish,” that carried the byline of Kurt Andersen, the author well known in media circles as a founder, with Mr. Carter and Thomas L. Phillips Jr., of Spy magazine.

The main problem with the article was that Mr. Andersen didn’t write it. He didn’t even know of its existence until his wife, Anne Kreamer, saw it while leafing through a Details at the gym and asked her husband why he hadn’t told her he was writing for that magazine.

Mr. Peres bragged about landing Mr. Andersen in the pages of Details in his editor’s letter, not having done the very editor in chief thing of reaching out personally to Mr. Andersen to thank him.

“The extra weird wrinkle,” said Mr. Andersen during a phone conversation last week, was that the magazine featured an “interview” of him among the short bios of that month’s contributors. “As well as the terrible piece attributed to me, there was an even worse, horrible, ‘Hey dude, it’s just gossip’ quote from me. It was mortifying. Not just mortifying. Grotesque.”

Mr. Andersen said of the magazine, “It was ahead of its time in terms of fake news fantasy-land alternative truth.”

One of Mr. Peres’s staffers, Bob Ickes, handled the editing of the article. (When contacted this week, Mr. Ickes said he did not write the piece published under Mr. Andersen’s name.)

“Mistakes happen at publications,” Mr. Peres said last week, while acknowledging his yearslong focus on drugs above work and all else. “Surely the magazine would not have been as good as it was if not for my staff. I know anyone who has spent any time around an addict has to spend a lot of time doing a lot of heavy lifting.”

Mr. Essex, the magazine’s former deputy, said it is not fair to portray Mr. Peres as having no involvement with the editorial product known as Details. “He could identify bizarre permutations of male behavior particularly at the epicenter of gay and straight,” Mr. Essex said.

This sort of “male anthropology,” as Mr. Essex called it, did get Mr. Peres in trouble sometimes, like when he assigned to a staffer a 2004 piece titled “Gay or Asian?” that drew protesters to picket outside of the Condé Nast headquarters. “It was a tremendous lapse of judgment,” Mr. Peres said.

But cancel culture was not yet ascendant, and he stayed atop the masthead for another 11 years.

“You know when you’re in dysfunctional family and it’s the only family you know so you think that’s how all families are?” Ms. Ozturk said of working at Details then. “It was like that.”