Hi, I need some help please. here is what i want to do: 1. im making a script which will generate bulk id card populating the data from the database and displaying data to a single template and will generate that id cards in return. here is my script: $sql = mysqli_query($con, "SELECT * FROM employees"); header('Content-type: image/png'); $image = imagecreatefrompng('id-template.png'); $color = imagecolorallocate($image, 0, 0, 0); imagepng($image); while($rs = mysqli_fetch_assoc($sql)){ imagettftext($image, 13, 0, 60,117, $color, $font, $rs['empname']); //employee name location of the template $save = "id/".strtolower($rs['id']).".png"; imagepng($image, $save, 9, PNG_NO_FILTER); } PHP: This produces id card, but the data passed to each id card overlaps with the other. Please help me fix this problem. Thank you
It would have been nice to see a screenshot of what you mean. And also to put your code in code tags. However, just looking at the code, I see the most likely cause. The problem comes from here. imagettftext($image, 13, 0, 60,117, $color, $font, $rs['empname']); PHP: The imagettftext function writes text to an image starting from a certain x and y coordinate. Meaning that parameter 4 (in your code, 60) or parameter 5(in your code, 117) should change during each iteration depending on how you want the final out put to be. Those are the x and y coordinates respectively. For example, do this if you want the bulk id cards to line up vertically: $yCord = 117; while($rs = mysqli_fetch_assoc($sql)){ imagettftext($image, 13, 0, 60, $yCord, $color, $font, $rs['empname']); //employee name location of the template $save = "id/".strtolower($rs['id']).".png"; imagepng($image, $save, 9, PNG_NO_FILTER); /* Add to $yCord variable here. */ $yCord += 200; //Adjust it until it looks perfect } PHP: Hope that helps. Please share a screenshot so we can be sure of exactly how you want it to appear
after you save the card you need to re-create the variable so that it's fresh. Your line 15 (currently blank) should be $image = imagecreatefrompng('id-template.png'); PHP:
What do ID cards have to do with generating a composite IMAGE. Can't you just do the layout in the markup, or is this something you need as a single file for people to save? Generally when using web technologies? Using images to display text is usability and accessibility shit. And unreliable, and poor scaling depending on the media target. To me this doesn't look like anything that should be done server-side in the first place.