We will keep photos of students in one folder photos( download the zip file at the end of this page with sample photos ) . File name of the photos are same as student id like . 1.jpg, 2.jpg .... This is done to maintain unique photos against each student as there is a possibility that name of two students can be same.
We created the path by using file name with directory name in above code and then by using imagecopy() the same is added at a location ( x=60, y=310 ) of the source image.
Adding Logo
If Logo is common in all certificates then it is better to add the same to main template. However to understand the process of adding images dynamically this code is used.