我正在使用Imagine库进行一些图像实时编辑,并且正在碰壁了解如何解耦我可能需要动态构建多个实例的类。
人为的例子
namespace App;
use Imagine\Image\{ Point, ImagineInterface };
use Imagine\Image\Palette\PaletteInterface;
class Image
{
protected $imagine;
protected $palette;
public function __construct(ImagineInterface $imagine, PaletteInterface $palette)
{
$this->imagine = $imagine;
$this->palette = $palette;
}
public function buildImage($args)
{
$image = $this->imagine->open('some/file/path');
$font = $this->imagine->font('some/font/path', 20, $this->palette->color('#000'));
/* how to inject these when x/y are dynamically set? */
$point1 = new Point($args['x1'], $args['y1']);
$point2 = new Point($args['x2'], $args['y2']);
$image->draw()->text('example one', $font, $point1);
$image->draw()->text('example one', $font, $point2);
}
}