Bill Cunningham shoots on the street in New York City in a scene from the 2010 documentary "Bill Cunningham New York." (First Thought Films/Zeitgeist Films/First Thought Films/Zeitgeist Films)

Bill Cunningham, who dropped out of Harvard to pursue a career making hats for high-society women and later became a roving street fashion photographer for the New York Times, documenting — and at times influencing — fashion trends with his keen eye for emerging styles, died June 25 in New York City. He was 87.

His death was announced by the Times. The cause was complications from a stroke.

For decades Mr. Cunningham photographed New York’s social, philanthropic and fashion whirl for the Times. Zipping across the Big Apple on his bicycle, armored in his signature blue French workman’s jacket, his Nikon camera dangling around his neck, he discreetly photographed the most fashion-forward people in one of the world’s most stylish cities.

In addition to documenting street fashion, Mr. Cunningham also captured on camera the larger culture of the city and was one of the first photographers to document gay pride parades and AIDS awareness gatherings in the 1980s.

Physically unimposing and almost comically frugal, Mr. Cunningham was as much a character as anyone he photographed. The product of a devout Irish-Catholic family in Boston, he attended Harvard University only to confound expectations by quitting in 1948 after one term to focus on his interest in women’s hats.

He became a milliner and also worked at an exclusive dress shop in Manhattan whose clients included Marilyn Monroe, Katharine Hepburn and future first lady Jacqueline Kennedy. He befriended Kennedy, who turned to Mr. Cunningham after her husband’s assassination in 1963 for help dyeing a red Dior or Balenciaga suit — he never could remember which — a more somber color for the president’s state funeral.

“There wasn’t time to get another suit, so we dyed it black,” he told Harper’s Bazaar in 2014.

Mr. Cunningham drifted into journalism at the behest of his society friends, writing about fashion for Women’s Wear Daily and the Chicago Tribune, among other publications. A self-taught photographer, he began regularly contributing pictures to the Times in the 1970s.

As far as the editors were concerned, his breakthrough — apparently unintentional — was his 1978 picture of the actress Greta Garbo, the enigmatic movie star of the 1920s and 1930s who famously abandoned the screen for life as a recluse.

Enamored of Garbo’s nutria coat, Mr. Cunningham said he had barely noticed the woman herself when he took a photo of her on the streets of New York.

“I thought: ‘Look at the cut of that shoulder. It’s so beautiful,’ ” he later wrote. “All I had noticed was the coat, and the shoulder.”

At the Times, which he joined full-time in 1993, Mr. Cunningham had two weekly photographic columns. “Evening Hours” focused on the city’s social and philanthropic scene, and “On the Street” captured the self-made fashions of stylish New Yorkers strolling through the city.

Mr. Cunningham’s photography of unpredictable urban fashion trends earned him a loyal following and made him internationally renowned as a trend-spotter, long before new looks were identified by more renowned fashion editors.

“I realized that you didn’t know anything unless you photographed the shows and the street, to see how people interpreted what designers hoped they would buy,” Mr. Cunningham said in the 2010 documentary film “Bill Cunningham New York.”

He said his favorite time to capture New Yorkers was when they were off guard, particularly in the rain or during a blizzard. He also enjoyed photographing unsuspecting fashionistas on their way to work early in the morning.

“You see how people really live and how they really dress,” he said.

William John Cunningham Jr. was born in Boston on March 13, 1929. He described his Irish-Catholic family as deeply religious and said his interest in fashion developed at church.

“I could never concentrate on Sunday church services because I’d be concentrating on women’s hats,” he wrote in an autobiographical column in the Times in 2002.

He left Harvard at 19 and moved to New York to work as a hat designer, then as a fashion consultant at a custom dress boutique. He later opened a millinery shop under the name “William J.” to save his family from embarrassment, he said.

He specialized in whimsical, avant-garde hat wear — from a giant clamshell hat to feathery headpieces to turban-inspired toppers. The store drew praise from the Times, where a critic in 1958 noted that Mr. Cunningham had “cornered the face-framing market with some of the most extraordinarily pretty cocktail hats ever imagined.”

After closing his shop in 1962, Mr. Cunningham began working in journalism, gradually switching from newspaper columns to photo spreads. His work was featured in Women’s Wear Daily, Vogue and the original Details magazine, which once devoted more than 40 pages to his pictures.

Between 1968 and 1976, he worked on a historical project called “Facades” that linked fashion to architecture. He captured models in period clothing to match the eras of Manhattan structural landmarks dating from the 18th century to the 1950s. Among his models was photographer Editta Sherman, whom he once called “the kind of woman who performed ‘The Dying Swan’ as a hobby.”

The visual project was turned into a book in 1978 and a celebrated photo exhibition at the New-York Historical Society in 2014. He was profiled in the New Yorker in 2009 and was named a “living landmark” of New York by the New York Landmarks Conservancy.

In the documentary on his life, Mr. Cunningham was portrayed as old-fashioned, frugal and resistant to advances in technology. He refused to own a cellphone, a computer or a television. He insisted on having his film developed at a one-hour photo store in Manhattan, taking a fresh batch of negatives to his office at the Times each week.

For six decades, he lived in a rent-controlled artist’s space in Carnegie Hall with no kitchen. He used a communal bathroom and slept in a cramped single bed that rested on filing cabinets filled with old negatives. In 2007, the Carnegie Hall Corp. announced plans to demolish the studios for rehearsal spaces, and Mr. Cunningham left for an apartment in Midtown.

He had no immediate survivors.

In 2008, Mr. Cunningham was honored by the French culture ministry for his career in fashion photography and was awarded the Legion of Honor. As he stepped to the podium to accept his award, he was actively photographing the crowd of fashion industry officials.

“It’s as true today as it ever was,” he said in his acceptance speech, his voice breaking. “He who seeks beauty will find it.”