A policeman has been spared prison after admitting having nearly 9,000 indecent images of children.
PC Stephen McGoldrick, 50, quit Gloucestershire Police after he was charged with five counts of making indecent images of children.
McGoldrick, from Aberdare, south Wales, was sentenced to an 18-month community order with 40 days of rehabilitation
Judge Peter Blair said although he had "fallen from grace in a massive way" he had shown "considerable remorse".
"These were abhorrent images which I believe you now acknowledge and understand have real victims," he told Bristol Crown Court.
"You must understand that I impose this sentence because I have concluded there is a good prospect of rehabilitation which can be best achieved through a community order rather than a custodial sentence."
McGoldrick was also ordered to carry out 150 hours of unpaid work and placed on the sex offenders register for five years.
The court heard indecent images were recovered from a mobile phone belonging to McGoldrick when police were investigating a separate matter in April this year.
That led to search warrants being carried out in June where several electronic devices were seized.
McGoldrick, who joined Gloucestershire Police in 2008, resigned before he was charged in July and pleaded guilty at Bristol Magistrates' Court last month.
In mitigation, defence lawyer James Haskell, said: "He knows it was wrong but was clearly in a very bad way and in his own words, he was on a path to self-destruction."