For two days before President Trump’s visit on Thursday to a Ford factory in Michigan, controversy raged over whether he would — or should — wear a surgical mask while he was there.

Ford had put out the word that masks were mandatory in the Ypsilanti factory — which is making personal protective equipment — though Trump had previously made it clear that, counter to federal recommendations and Michigan law, he didn’t see masks as his kind of thing. So the Michigan attorney general put out a statement imploring the president to comply.

Would he or wouldn’t he? Trump played coy on Tuesday: “It depends, I mean, you know, certain areas I would and certain areas I don’t . . .”

Had there ever been so much drama over the logistics of a basic photo op?

For that was essentially what was at stake Thursday — the subtle visuals of a particular presidential appearance, and the message it would send across the land. The entire point of the trip — as with so many ventures by politicians into the real world — was the photos.

By ultimately not wearing a mask in front of the cameras at Ford, Trump managed to subvert the carefully arranged “optics” of the visit — which for any other president would serve as a feel-good story about leadership, corporate nimbleness and the production of lifesaving medical gear. Instead, his mask-querade dominated news coverage.

Political photo ops are, by definition, artificial and self-consciously orchestrated events, designed to goose the news media into paying attention to whatever story line the White House or a campaign wants to promote.

“The people were out in droves and their spirits are high,” Ronald Reagan wrote in his diary about a 1983 trip he had made that day to flood-ravaged Louisiana. “I shoveled a few sandbags for the cameramen.”

It was a rare acknowledgment of the calculation, even cynicism, behind photo ops. Reagan had been on his way back to Washington after a visit to California when communications director Michael Deaver urged him to make a disaster-zone detour. Reagan could just as easily have helped Louisiana from the White House — but visiting the state offered the photographic proof that he cared, and that the nation should, too.

A president listening intently to a fellow world leader. A candidate laughing with school kids. Tossing a football. Serving dinner to the troops. Political photo ops happen so often and the images are so prevalent — until, of course, a national health crisis renders them scarce — that we hardly stop to think about the stagecraft that goes into them.

Three decades later, the nation has another president who, like Reagan, has roots in show business and a knack for the visual. Yet time and again, Trump has managed to step on the careful planning of his communications staff. On a visit to Puerto Rico to view the devastation of Hurricane Maria, he casually flipped paper-towel rolls to survivors. He stared into the solar eclipse without eye protection. And when a kid dressed as a Minion came trick-or-treating to the White House last year, Trump dropped a candy bar on the kid’s head instead of in his bag. Each time, the result was a story that upstaged the intended image of a president doing presidential things.

Presidents have been exploiting the power of the visual ever since photography was invented — Matthew Brady helped Abraham Lincoln improve his image with a famously glammed-up campaign portrait in 1860. The practice soon came to encompass exotic locations and props — a championship team, a celebrity, a baby, a live turkey in the Rose Garden. Deaver turned Reagan into the embodiment of Americana by sending him in front of the news cameras to clear brush on his ranch or ride horses. He gave speeches with iconic backdrops — an overlook of Omaha Beach on the 40th anniversary of D-Day, the South Bronx to advocate for urban renewal, the Berlin Wall at the height of the Cold War. ("Mr. Gorbachev, tear down this wall!") Deaver even made a photo op of Reagan's 2004 burial, timing it to the hour of the sun setting over the Pacific Ocean.

“A compelling picture can immediately and easily drive a message,” said Ari Fleischer. “It’s instantly understood. No headline is necessary. No words get in the way. And often it’s emotional, which is what makes it compelling.” (Deaver, in fact, used to assess the success of his Reagan photo ops by watching the TV reports with the sound off.)

Fleischer’s time as George W. Bush’s White House press secretary coincided with two of the most memorable political photo ops of recent vintage. A few days after the Sept. 11, 2001 terrorist attacks, Bush stood amid the rubble of the World Trade Center with a bullhorn and an arm slung around a New York City firefighter. (“I can hear you!” he shouted. “And the people who knocked these buildings down will hear all of us soon.”) The moment conveyed resilience, caring and strength — and much of it, Fleischer said, was spontaneous.

The second decidedly was not. A few weeks after the invasion of Iraq in 2003, a flight-suit-clad Bush landed in a Navy jet on the carrier USS Abraham Lincoln — a “Top Gun” entrance later overshadowed by banner that read “Mission Accomplished.” Critics called the message arrogant and premature; Bush later regretted it.

Almost every appearance by the president is technically a photo op (short for “opportunity”), including Oval Office pool “sprays” — when photographers scramble to take a few shots of the president with some other worthy before being shooed away. Strictly speaking, however, photo ops are more elaborate events beyond the White House gates crafted as “visual presentations of the president doing the job and having an impact,” as Joe Lockhart, one of President Bill Clinton’s press secretaries, puts it. It’s a template often simulated by the candidates who aspire to become president.

The basic playbook isn’t hard: Associate the politician with something grand or profound or tragic or just relevant to whatever agenda he is trying to set. Placing him at the scene of a natural disaster or the factory floor is a good start, but he also has to do something — hand out supplies, hug people, walk around in a windbreaker with a concerned expression.

What could go wrong?

Photo flops — or maybe "photo oops" — have bedeviled politicians since the dawn of the TV age. Think of President Nixon's "casual birthday stroll" on the beach near his home in San Clemente, Calif., wearing black wingtips and dress pants. Or Michael Dukakis, the 1988 Democratic nominee, looking small and nebbish riding in a tank.

Even Reagan had his Bitburg. In 1985, Reagan agreed to visit a German cemetery near Bitburg, West Germany, as a way to demonstrate American-German solidarity. A problem arose, however, with the news that the cemetery was the final resting place of 49 members of Hitler’s murderous Waffen SS. Plans for the visit prompted outrage, but Reagan refused to back down. To blunt the criticism, Deaver added another photo op to the schedule — a respectful stop at the Bergen-Belsen concentration camp.

In that case, the problem wasn’t with the photo. It was the story that came out of the photo op. Which is where Trump has found trouble time and again.

He evoked the solemn visuals befitting a president at the 75th anniversary commemoration of the D-Day invasion in Normandy — but ended up giving a television interview from the U.S. military cemetery where he trashed House Speaker Nancy Pelosi with a field of white grave markers behind him. And that became the story that dominated half a day of news and punditry.

And the images of Trump wandering thoughtfully through a California town devastated by fire in 2018 were overshadowed by his off-the-cuff comments about how the state should “rake” its forest floors in the future.

Trump’s most grotesque photo op grew out of his visit to El Paso last year to comfort the survivors and families of a mass shooting. What should have been a layup — the president consoling the grieving — turned into a fiasco with a shocking photo: Trump grinning broadly and giving a thumbs-up sign as Melania Trump cradled a baby whose parents had been killed in the Texas shooting.

Trump had remained maskless in public throughout the pandemic — notably at a medical-mask factory in Phoenix on May 5 (despite signs posted around the facility reading “Attention: Face Mask Required in This Area”) and at a medical equipment factory in Allentown, Pa., last week, where virtually every other official and worker captured on camera was masked.

His reluctance could have something to do with masks emerging as a culture-war flash point: Democrats are far more likely than Republicans to say they wear a mask when leaving home. On Thursday, Trump told reporters that he did don a mask at the Ford plant during an off-camera part of the tour, “but I didn’t want to give the press the pleasure of seeing it.”

One reporter asked about the example it would set for the American public to see photos of him wearing a mask.

“I think it sets an example both ways,” Trump concluded.

It's been two months since Joe Biden's last photo op. And that one turned out to be a bit of a "photo oops" when a Detroit autoworker in a meet-and-greet scrum accused the Democratic candidate of "trying to take away our guns," and Biden snapped back at him with an expletive ("you're full of . . .") that briefly went viral.

Then came the pandemic. Since then, the mechanics involved in manufacturing photo ops — air travel, handshakes, crowds of fans, hugs — have brushed up against the parameters of stay-at-home orders and recommendations for social distancing.

Thus, Trump’s time on camera over the past two months has been mostly from the White House, through photo ops with people like truckers and health-care workers. His forays beyond the West Wing have involved a handful of factory and warehouse tours, as well as visits to the National Institutes of Health Vaccine Research Center and the departure of the U.S. Navy hospital ship Comfort from Norfolk.

The president has maintained a constant visual presence during the pandemic primarily via his daily briefings, befitting his background as a showman and his understanding of the power of images, said Adam Belmar, the deputy director of communications for production under President George W. Bush. “Presidential communication is inherently visual,” he said.

The next few months don’t seem very promising. With Trump restricted in his travel, Biden stuck in his house, rallies suspended and the political conventions in limbo, photo ops figure to be rare. Which raises a question: What does a presidential campaign even look like without them?

Elahe Izadi contributed to this story.