MILPITAS -- A Milpitas man who used a computer to paste photos of his 13-year-old daughter's head onto bodies of women in graphic poses shouldn't have been convicted of possessing child pornography because the pictures didn't show minors engaging in sex acts, a state appeals court ruled Wednesday.

California's child porn ban, punishable by up to three years in prison, "requires a real child to have actually engaged in or simulated the sexual act depicted," said the Sixth District Court of Appeal in San Jose.

The court said the law was intended to prevent exploitation of children. Interpreting it broadly to apply to computer-altered photos might violate the constitutional standard the U.S. Supreme Court established in 2002 when it struck down a federal law banning "virtual child pornography," sexually explicit images that were entirely computer-generated, the appellate panel said.

"Although we may find such altered images morally repugnant, we conclude that mere possession of them remains protected by the First Amendment," Justice Franklin Elia said in the 3-0 ruling.

The court ordered a Santa Clara County judge to resentence Joseph Gerber, convicted in 2009 of possessing child pornography and furnishing drugs to his daughter. He was sentenced to 13 years and four months in prison.

The court said the teenager's mother suggested to her daughter in 2008 that she work to build a relationship with the girl's father, Gerber, from whom the mother had been separated for about 12 years.

During their visits over the next few months, the girl said, Gerber gave her marijuana, which she had used before, and cocaine, which she wanted to try. During one of the drug sessions, she said, Gerber asked her to pose for pictures and she agreed, but she burst into tears when he told her to strip to her underwear.

She later told her mother, who called police. Officers who searched Gerber's home did not find photos of his daughter in her underwear, but saw pictures of her head superimposed on seven pornographic photos of women's bodies on a computer drive, the court said.

Gerber was convicted under a law prohibiting possession of any photo that depicts someone under 18 "personally engaging in or simulating sexual conduct."

Prosecutors argued that the altered photos depicted his daughter engaging in sex acts. But the court said the law's use of "personally" requires proof that a minor actually took part in those acts.

The court also overturned two of Gerber's three drug convictions, saying the trial judge had instructed jurors on the wrong law. Prosecutors could retry those counts and could also appeal Wednesday's ruling to the state Supreme Court.