Reputation: 35
I am using the Intervention Image Library to facilitate my card creation. For this I created a class where it would be easier to add texts on these cards.
Part of the code where this method is:
<?php
use Intervention\Image\ImageManagerStatic as Image;
class Cards Extends Image {
private $image;
[...]
public function addText($text, $x, $y, $textSize, $font, $color, $align, $valign, $angle) {
$this->image->text($text, $x, $y, function($font) {
$font->file($font);
$font->size($textSize);
$font->color($color);
$font->align($align);
$font->valign($valign);
$font->angle(0);
});
}
}
?>
My question is, I'm having trouble passing the arguments of the addText method to the function($font). How can I do this in PHP?
Upvotes: 2
Views: 38
Reputation: 78984
It appears that the callback for text() only accepts the Font object, so use use()
to pass them in:
$this->image->text($text, $x, $y, function($font) use($textSize, $color, $align, $valign)
{
$font->file($font);
$font->size($textSize);
$font->color($color);
$font->align($align);
$font->valign($valign);
$font->angle(0);
});
Upvotes: 2