31 lines
669 B
PHP
31 lines
669 B
PHP
|
<?php
|
||
|
|
||
|
namespace NoccyLabs\GdLabel\Elements;
|
||
|
|
||
|
use NoccyLabs\GdLabel\Element;
|
||
|
|
||
|
class ImageElement extends Element
|
||
|
{
|
||
|
|
||
|
protected $image;
|
||
|
|
||
|
protected function draw($gd, int $x, int $y, int $width, int $height, array $params)
|
||
|
{
|
||
|
$src = $this->getProp("src");
|
||
|
if (!$src || !\file_exists($src)) {
|
||
|
return;
|
||
|
}
|
||
|
if (!$this->image) {
|
||
|
$data = file_get_contents($src);
|
||
|
$this->image = imagecreatefromstring($data);
|
||
|
}
|
||
|
|
||
|
$sx = imagesx($this->image);
|
||
|
$sy = imagesy($this->image);
|
||
|
|
||
|
imagecopyresampled($gd, $this->image, $x, $y, 0, 0, $width, $height, $sx, $sy);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|