A US federal judge has ruled that Washington must release photographs showing abuse of detainees in Iraq and Afghanistan, in a longstanding court case on letting the world see potentially disturbing images of how the military treated prisoners.

US District Judge Alvin Hellerstein's decree on Friday gives the government, which has fought the case for over a decade, two months to decide whether to appeal before the photos could be released.

The American Civil Liberties Union (ACLU) has been seeking for several years to make them public in the name of holding government accountable.

The Defence Department is studying the ruling and will make any further responses in court, spokesman Myles Caggins III said.

ACLU representatives did not immediately respond to a request for comment on Friday night.

The ACLU has said the pictures "are manifestly important to an ongoing national debate about governmental accountability for the abuse of prisoners".

The fight over the photographs reaches back to the early years of the wars in Iraq and Afghanistan, and echoes the images of abuse at the Abu Ghraib prison in Iraq that sparked international outrage after they emerged in 2004 and 2006.

Early in the 2004 lawsuit, the ACLU pointed to the Abu Ghraib photos as priority examples of records the organisation was seeking on the treatment of detainees.

It is unclear how many more photographs may exist.

The government has said it has 29 relevant pictures from at least seven different sites in Afghanistan and Iraq, and it is believed to have perhaps hundreds or thousands more, Hellerstein said in a ruling in August.

He said some photos he had seen "are relatively innocuous while others need more serious consideration," and he has ruled that any images that would be released would be redacted to protect the identities of people in them.

Some photographs, taken by service members in Iraq and Afghanistan, were part of criminal investigations of alleged abuse.

Some images show "soldiers pointing pistols or rifles at the heads of hooded and handcuffed detainees," then-Solicitor General, now Supreme Court Justice, Elena Kagan, wrote in an appeal to the high court earlier in the case, which has taken a long road through the courts and Congress.

Incitement fears

The government has long argued that releasing the photographs could incite attacks against US forces and government personnel abroad, and officials have said that risk has not abated as the US military role in Iraq and Afghanistan lessened.

Indeed, "the danger associated with release of these photographs is heightened now," amid the rise of the Islamic State of Iraq and the Levant group (ISIL), Navy Rear Admiral  Sinclair Harris, the vice director for operations for the Joint Chiefs of Staff, said in a December court filing.

ISIL, he said "would use these photographs to further encourage its supporters and followers to attack US military and government personnel".

Amid the lawsuit, Congress passed a 2009 law allowing the government to keep the photos secret if the secretary of defence certified that unveiling them would endanger US citizens or government or military personnel.

Defence secretaries have since done so, but Hellerstein said the government has not been specific enough.

Source: Agencies