I'm creating a student ID card system, where each student will have his/her own.
For this I am using the intervention image, to pick up the student data and put in the standard ID card template.
The basic code for this I did was:
<?php
[...]
$card = Image::make('card_id-model.png');
$card->text('CARD ID', 20, 40, function($font) {
$font->file('arial.ttf');
$font->size(24);
$font->color('#fdf6e3');
$font->align('center');
$font->valign('top');
$font->angle(45);
});
$card->text('NAME: STUDENT\'S NAME', 20, 60, function($font) {
$font->file('arial.ttf');
$font->size(24);
$font->color('#fdf6e3');
$font->align('center');
$font->valign('top');
$font->angle(45);
});
$card->text('CODE: STUDENT\'S CODE', 20, 80, function($font) {
$font->file('arial.ttf');
$font->size(24);
$font->color('#fdf6e3');
$font->align('center');
$font->valign('top');
$font->angle(45);
});
$card->save('card_id - student\'s code.png');
This way is slower, considering that I will call the function every time I create the image. So I decided to instantiate the image first, since it will be used for all card id. Well, but I'm experiencing problems applying it in a loop to generate several at the same time since the texts are overwriting.
<?php
[...]
$card = Image::make('card_id-model.png');
$card->text('CARD ID', 20, 40, function($font) {
$font->file('arial.ttf');
$font->size(24);
$font->color('#fdf6e3');
$font->align('center');
$font->valign('top');
$font->angle(45);
});
for ($students as $student) {
$card->text('NAME: ' . $student->name, 20, 60, function($font) {
$font->file('arial.ttf');
$font->size(24);
$font->color('#fdf6e3');
$font->align('center');
$font->valign('top');
$font->angle(45);
});
$card->text('CODE: ' . $student->code, 20, 80, function($font) {
$font->file('arial.ttf');
$font->size(24);
$font->color('#fdf6e3');
$font->align('center');
$font->valign('top');
$font->angle(45);
});
$card->save('card_id - ' . $student->code . '.png');
}
That was the best and quickest way I found to mass-generate. Anybody got any tips?