A German court has convicted a man of committing a war crime after he posed for photos with severed heads in Syria. The 21-year-old, a German with Iranian roots, was sentenced to two years in prison.

The Frankfurt state court said Tuesday the defendant, identified only as Aria L. in line with German privacy rules, traveled to Syria in 2014 and spent at least three weeks with an Islamic extremist fighting government forces.

In March or April 2014, a group of fighters attacked a checkpoint in Idlib province. They captured two soldiers and beheaded them, then impaled the heads on spikes.

The court found that the defendant posed with the heads for three photos, one of which was shared on Facebook. The photos also were found on his mother's cellphone.