Initial commit
This commit is contained in:
31
src/Elements/ImageElement.php
Normal file
31
src/Elements/ImageElement.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user