A Texas teacher, who told federal agents he used child pornography to cope with depression after his wife died, lost his bid Wednesday to be released on bail.

Mark Anthony Rodriguez, 52, a former San Antonio-area teacher and principal, has remained in federal custody since last week. On August 8, he was indicted on five counts of possession, promotion, and distribution of child pornography that depicted youngsters forced into acts of bondage and bestiality.

The San Antonio Express-News reported Rodriguez taught fifth and sixth grade biology at Losoya Intermediate from December 2015 until December 2017, according to the Southside Independent School District. Previously, he worked at Southside High School as a special education aide and, later, in student support services from September 2012 to June 2014. Rodriguez was employed by South San Antonio ISD holding positions such as middle school principal and instructional technological specialist from 1991 to 2011.

On December 1, 2017, Homeland Security Investigations (HSI) informed Southside ISD police that the teacher was under investigation. Rodriguez wound up on their radar during a ongoing child porn sting. Agents pinpointed a user accessing online images from a device in Rodriguez’s home. On December 4, the school district placed him on administrative leave. The next day, Rodriguez resigned effective December 15.

During the investigation, Southside ISD turned over the computers Rodriguez used at school but detectives found no evidence of child pornography. However, when federal agents obtained a search warrant for Rodriguez’s home and seized his electronic devices, cellphones, and computers, they discovered 4,700 sexually explicit images and more than 380 child porn videos. The feds located even more pornographic content in Rodriguez’s Dropbox and personal email accounts.

On August 21, Rodriguez appeared in federal court. U.S. Magistrate Judge Henry Bemporad ordered him to remain in custody until the bail hearing.

At Wednesday’s hearing, George Aristotelidis, the lead defense attorney for Rodriguez, asked U.S. Magistrate Judge Richard Farrer to release his client on bail, remanding him into the custody of Rodriguez’s mother. The lawyer requested the judge impose house arrest with electronic monitoring. Aristotelidis said federal jail was not a suitable place for Rodriguez as he suffered with back problems and weighed more than 400 pounds, according to the Express-News.

HSI Special Agent Joel Juvette testified that Rodriguez accessed child porn since at least June 2016. The indictment identified the illegal activities took place between June 6, 2016, and December 2, 2017. Federal prosecutors also alleged Rodriguez spoke to individuals with whom he shared pornography about having sex with children.

Rodriguez explained his behavior by telling the feds he went through a rough patch when his wife died of brain cancer a few years ago.

“He admitted that to deal with the depression, he would view and possess child pornography,” said Juvette.

Tracy Thompson, U.S. Assistant Attorney for the Western District of Texas, urged the judge to keep Rodriguez in federal custody. “There is a great danger in that this is a man who views child porn at night and then went into a classroom full of children roughly as those he told others he wanted to have sex with,” said Thompson.

Farrer told the defense team he would consider granting bail to Rodriguez if conditions changed. However, the judge was not so quick to release Rodriguez. He expressed concerns about the children who lived near and around the home of Rodriguez’s parents. Ultimately, he denied the bail request.

Follow Merrill Hope, a member of the original Breitbart Texas team, on Twitter.