So I have a file named "names.txt" with multiple lines. Each line contains one name. I also have one mockup image named "participant.jpg"
And here it`s my code:
<?php
$handle = fopen("names.txt", "r");
function create_img($line)
{
$im = imagecreatefromjpeg("./images/participant.jpg");
$textcolor = imagecolorallocate($im, 0, 0, 0);
// Write the string at the top left
imagettftext($im, 50, 0, 80, 640, $textcolor, 'nexa.ttf', $line);
imagejpeg($im, './uploads/' . $line . '.jpg');
imagedestroy($im);
}
if ($handle) {
while (($line = fgets($handle)) !== false) {
create_img($line);
}
} else {
die('Cannot open file..');
}
?>
So for every new line I want to create a specific photo and "upload" it to my uploads folder.
It only creates the image for the last line and for the rest it returns me this error:
Warning: imagejpeg() [<a href='function.imagejpeg'>function.imagejpeg</a>]: Unable to open './uploads/Botond.jpg' for writing: Invalid argument in C:\lab\ccc-badges\badges.php on line 12
This is some $line outputs
Alina Popescu
Adrian Oltean
Patricia-Andrada Leven
Stanescu Gheorghe
'./uploads/'.$line.'.jpg'before line 12$lineaspecially the last one? I meanecho $line,'<br>';imagejpeg($im, './uploads/' . trim($line) . '.jpg');when writing in a file