Allow to resize marker.
This commit is contained in:
parent
0752c0cca7
commit
a339f86493
@ -13,11 +13,27 @@ class ExtraMarkerPrinter
|
|||||||
/** @var ExtraMarker $marker */
|
/** @var ExtraMarker $marker */
|
||||||
protected $marker = null;
|
protected $marker = null;
|
||||||
|
|
||||||
|
/** @var int $baseMarkerWidth */
|
||||||
|
protected $baseMarkerWidth = 72;
|
||||||
|
|
||||||
|
/** @var int $baseMarkerHeight */
|
||||||
|
protected $baseMarkerHeight = 92;
|
||||||
|
|
||||||
|
/** @var float $markerSize */
|
||||||
|
protected $markerSize = 0.75;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setMarkerSize(float $markerSize): ExtraMarkerPrinter
|
||||||
|
{
|
||||||
|
$this->markerSize = $markerSize;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setMarker(AbstractMarker $marker): ExtraMarkerPrinter
|
public function setMarker(AbstractMarker $marker): ExtraMarkerPrinter
|
||||||
{
|
{
|
||||||
$this->marker = $marker;
|
$this->marker = $marker;
|
||||||
@ -35,10 +51,21 @@ class ExtraMarkerPrinter
|
|||||||
$markerWidth = imagesx($markerImage);
|
$markerWidth = imagesx($markerImage);
|
||||||
$markerHeight = imagesy($markerImage);
|
$markerHeight = imagesy($markerImage);
|
||||||
|
|
||||||
$destX -= $markerWidth / 2;
|
$destX -= $markerWidth * $this->markerSize / 2;
|
||||||
$destY -= $markerHeight;
|
$destY -= $markerHeight * $this->markerSize;
|
||||||
|
|
||||||
imagecopy($canvas->getImage(), $markerImage, $destX, $destY, 0, 0, imagesx($markerImage), imagesy($markerImage));
|
imagecopyresampled(
|
||||||
|
$canvas->getImage(),
|
||||||
|
$markerImage,
|
||||||
|
$destX,
|
||||||
|
$destY,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$markerWidth * $this->markerSize,
|
||||||
|
$markerHeight * $this->markerSize,
|
||||||
|
$markerWidth,
|
||||||
|
$markerHeight
|
||||||
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -48,17 +75,23 @@ class ExtraMarkerPrinter
|
|||||||
$extramarkersImgUrl = __DIR__.'/../../../images/extramarkers.png';
|
$extramarkersImgUrl = __DIR__.'/../../../images/extramarkers.png';
|
||||||
$extramarkers = imagecreatefrompng($extramarkersImgUrl);
|
$extramarkers = imagecreatefrompng($extramarkersImgUrl);
|
||||||
|
|
||||||
$markerImage = imagecreatetruecolor(72, 92);
|
$markerImage = imagecreatetruecolor($this->baseMarkerWidth, $this->baseMarkerHeight);
|
||||||
$transparentColor = imagecolorallocatealpha($markerImage, 0, 0, 0, 127);
|
$transparentColor = imagecolorallocatealpha($markerImage, 0, 0, 0, 127);
|
||||||
imagefill($markerImage, 0, 0, $transparentColor);
|
imagefill($markerImage, 0, 0, $transparentColor);
|
||||||
|
|
||||||
$markerWidth = imagesx($markerImage);
|
$sourceX = $this->baseMarkerWidth * $this->marker->getColor();
|
||||||
$markerHeight = imagesy($markerImage);
|
$sourceY = $this->baseMarkerHeight * $this->marker->getShape();
|
||||||
|
|
||||||
$sourceX = $markerWidth * $this->marker->getColor();
|
imagecopy(
|
||||||
$sourceY = $markerHeight * $this->marker->getShape();
|
$markerImage,
|
||||||
|
$extramarkers,
|
||||||
imagecopy($markerImage, $extramarkers, 0, 0, $sourceX, $sourceY, $markerWidth, $markerHeight);
|
0,
|
||||||
|
0,
|
||||||
|
$sourceX,
|
||||||
|
$sourceY,
|
||||||
|
$this->baseMarkerWidth,
|
||||||
|
$this->baseMarkerHeight
|
||||||
|
);
|
||||||
|
|
||||||
$this->writeMarker($markerImage);
|
$this->writeMarker($markerImage);
|
||||||
|
|
||||||
@ -78,7 +111,5 @@ class ExtraMarkerPrinter
|
|||||||
|
|
||||||
$white = imagecolorallocate($markerImage, 255, 255, 255);
|
$white = imagecolorallocate($markerImage, 255, 255, 255);
|
||||||
imagettftext($markerImage, $fontSize, 0, $x, $y, $white, $fontFile, $text);
|
imagettftext($markerImage, $fontSize, 0, $x, $y, $white, $fontFile, $text);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user