Almost a third of offenders tested positive for illegal drugs when they left prison last year, according to new figures.

The statistics, published by the Scottish Public Health Observatory, found of the 633 people tested when leaving jail in a one-month period in 2016/17, 30% were positive for illegal drugs, including the illicit use of prescription drugs.

The proportion has gradually increased since 2009/10, when the figure stood at 17%, and is up on 2015/16 when 27% tested positive.

Addiewell Prison in West Lothian recorded the highest rate last year, with more than half of those leaving testing positive for illegal drugs.

The drugs most commonly detected when leaving prison were buprenorphine, used to treat addiction and found in 12% of tests, cannabis - detected in 9% of tests - and opiates such as heroine, also found in 9% of tests.

The data also shows just over three-quarters of the 1,026 people arriving at prison in a one-month period last year tested positive for illegal drugs.

Since 2010/11, the proportion testing positive when entering prison has been relatively stable, ranging between 70% and 77%.

A statement from the Scottish Prison Service said: "Recovery is the explicit aim of all services providing treatment and rehabilitation for prisoners with drug problems.

"A range of substance misuse treatment and support services are provided by adopting a multi-disciplinary approach.

"A comprehensive range of robust security measures are in place to prevent the introduction of contraband into our prisons.

"Significant investment continues to be made in the development of new technology and staff training to detect, deter and reduce the availability and supply of illegal drugs.

"Anyone found in possession of contraband is reported to the appropriate authorities."