A Michigan pervert defended himself over a stash of kiddie porn found on his computer — claiming he identifies as an 8-year-old girl, according to a report.

Joseph Gobrick, 45, put up the bizarre defense in Kent County court before he was sentenced last week to up to 20 years in prison, news station WZZM reported on Thursday.

“I’ve always been an 8-year-old girl,” Gobrick told the court. “And even my drawings and fantasies, I am always an 8-year-old girl.”

Prosecutors allege at least eight minors were identified in graphic images on Gobrick’s computer at his Grand Rapids home. Children as young as infants were seen being sexually assaulted in the trove of kiddie porn.

He was found guilty of three counts of child sexually abusive commercial activity and using a computer to commit a crime.

Representing himself in court, Gobrick claimed the images were computer-animated and protected under the First Amendment, the outlet reported.

“I would no sooner have sex with a child than you would with a rattlesnake,’’ he told the judge. “It’s just not safe.”

But Kent County Assistant Prosecutor Daniel Helmer argued that Gobrick was “a danger to the public,” claiming that he talked about and drew images of child rape while in jail.

Kent County Circuit Court Judge Paul Denenfeld sentenced Gobrick to between 10 and 20 years behind bars, saying he showed zero remorse.

“Based on everything he’s said and done, including bragging about what he was drawing in his cell, he obviously doesn’t think child sexually abusive material is wrong,’’ Denenfeld said. “This isn’t just virtual stuff; this is also real people being harmed.’’

Gobrick is a sex offender with a prior conviction from a 2001 case for sexual abuse in New York, WZZM reported.