White House photographer Pete Souza has spoken about snapping a poignant photo of Barack Obama in front of a rainbow in Jamaica, where homosexuality is illegal.

During a visit to the country – where gay people face up to ten years in prison – the US President was snapped waving in front of a rainbow, leading the image to go viral.

The image was released as the White House’s official ‘Photo of the Day’ following the trip – in which Obama also raised Jamaica’s gay rights record and met with LGBT citizens.

In a new blog, Pete Souza – the White House photographer who snapped the pic – revealed he had planned it in advance.

He wrote: “Every once in a while, you also just get very lucky. Such was the case last week, when a rainbow came along just as the President’s helicopter was arriving at the airport in Kingston, Jamaica, where he would board Air Force One for the flight to Panama.

“Fortunately, I was manifested aboard the second helicopter–which always arrives before Marine One–giving me a few minutes to prepare for photographing the rainbow.

“After photographing the departure greets, I ran under the wing of the plane to try and line up where the President would be when he waved goodbye at the top of the stairs.

He continued: “I guessed right where the President would land when he waved, with his right hand framed right in the middle of the rainbow.”

The aptly-timed photo op comes as the White House installed a gender-neutral toilet in the Eisenhower Executive office Building – next door to the West Wing – which can be used by employees and White House guests.

Earlier this week President Barack Obama called for an end to “conversion” therapies which aim to change the sexual orientation or gender identity of LGBT youths.

Also this week, an Executive Order signed by Obama that outlaws anti-LGBT discrimination among federal contractors yesterday came into effect.

The Prime Minister of Jamaica recently claimed that her country “respects” the rights of gay people – despite going back on her own pledge to decriminalise homosexuality.