"1000 likes or I will drop him", a man pictured holding a baby out of a 15th-floor window in Algeria proclaimed.

An Algerian man has been sentenced to two years in prison for dangling a baby out of a high-rise window to get Facebook "likes".

The man posted a picture of himself holding the baby out of the window on the 15th-floor of the building with the caption: "1,000 likes or I will drop him," news website Al-Arabiya reported.

He was charged with endangering the baby's safety following his arrest on Monday (NZ time), police said.

The picture, taken in the capital Algiers, caused a social media uproar with many demanding he be convicted of child abuse.

READ MORE:

* Michael Jackson's kids recall pop star dad

* US woman charged US$39.95 for holding her baby in hospital

​* You can never hold your baby too much, says study

The man, a relative of the baby, denied the child's life was put at risk.

He claimed the images had been altered by social media users, Algeria's Ennahar TV reported.

"The picture was taken in a balcony with protective barriers," the man said. "These were removed."

The child's father also testified at court, saying he did not want the man to be sent to jail.

The man had just been playing a game, the father said.

However, the judge said the man needed to be imprisoned.

The picture was clear - the child's life was in danger, the judge said.