mirror of
https://github.com/Karaka-Management/oms-Labeling.git
synced 2026-01-11 17:18:41 +00:00
todos fixed
This commit is contained in:
parent
9de0498391
commit
07972d72ae
|
|
@ -30,8 +30,18 @@ class Image
|
|||
|
||||
public float $ratio = 0.0;
|
||||
|
||||
public float $rotate = 0.0;
|
||||
|
||||
public int $width = 0;
|
||||
|
||||
public int $height = 0;
|
||||
|
||||
public int $x1 = 0;
|
||||
|
||||
public int $x2 = 0;
|
||||
|
||||
public int $y1 = 0;
|
||||
|
||||
public int $y2 = 0;
|
||||
|
||||
public string $src = '';
|
||||
|
|
|
|||
103
Models/Label.php
103
Models/Label.php
|
|
@ -67,8 +67,7 @@ class Label
|
|||
|
||||
// @todo: replace int type with enum
|
||||
if ($element instanceof Shape) {
|
||||
if ($element->type === 1) {
|
||||
// Line
|
||||
if ($element->type === ShapeType::LINE) {
|
||||
if ($element->borderThickness === 1) {
|
||||
\imageline($im, $element->x, $element->y, $element->x2, $element->y2, $color);
|
||||
} else {
|
||||
|
|
@ -79,8 +78,7 @@ class Label
|
|||
$color
|
||||
);
|
||||
}
|
||||
} elseif ($element->type === 2) {
|
||||
// Rectangle
|
||||
} elseif ($element->type === ShapeType::RECTANGLE) {
|
||||
\imagefilledrectangle(
|
||||
$im,
|
||||
$element->x, $element->y,
|
||||
|
|
@ -96,9 +94,23 @@ class Label
|
|||
$bg
|
||||
);
|
||||
}
|
||||
} elseif ($element->type === ShapeType::ELLIPSE) {
|
||||
if ($element->fillColor === -1) {
|
||||
\imageellipse(
|
||||
$im,
|
||||
$element->x, $element->y,
|
||||
$element->x2, $element->y2,
|
||||
$bg
|
||||
);
|
||||
} else {
|
||||
\imagefilledellipse(
|
||||
$im,
|
||||
$element->x, $element->y,
|
||||
$element->x2, $element->y2,
|
||||
$bg
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// @todo: implement circle + elipse
|
||||
} elseif ($element instanceof Text) {
|
||||
\imagettftext($im, $element->size, 0, $element->x, $element->y, $color, $element->font, $element->text);
|
||||
} elseif ($element instanceof Image) {
|
||||
|
|
@ -107,27 +119,66 @@ class Label
|
|||
return null;
|
||||
}
|
||||
|
||||
\imagealphablending($in, false);
|
||||
\imagesavealpha($in, true);
|
||||
|
||||
$transparency = \imagecolorallocatealpha($in, 0, 0, 0, 127);
|
||||
if ($transparency === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$srcW = \imagesx($in);
|
||||
$srcH = \imagesy($in);
|
||||
|
||||
// should resize
|
||||
// @todo: impl. skewing
|
||||
if ($element->ratio !== 0.0 || $element->x2 !== 0 || $element->y2 !== 0) {
|
||||
$ratio = $element->ratio;
|
||||
if ($ratio === 0.0) {
|
||||
$ratio = ($element->x2 - $element->x) / $srcW;
|
||||
}
|
||||
// should crop
|
||||
if ($element->x1 !== 0 || $element->x2 !== 0 || $element->y1 !== 0 || $element->y2 !== 0) {
|
||||
$cropped = \imagecrop($in, [
|
||||
'x' => $element->x1,
|
||||
'y' => $element->y1,
|
||||
'width' => $element->x2 === 0 ? $srcW - $element->x1 : $element->x2 - $element->x1,
|
||||
'height' => $element->y2 === 0 ? $srcH - $element->y1 : $element->y2 - $element->y1,
|
||||
]);
|
||||
|
||||
$newW = (int) ($srcW * $ratio);
|
||||
$newH = (int) ($srcH * $ratio);
|
||||
|
||||
$newIn = \imagecreatetruecolor($newW, $newH);
|
||||
/*
|
||||
$newIn = \imagecreatetruecolor($crop['width'], $crop['height']);
|
||||
if ($newIn === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$transparency = \imagecolorallocatealpha($newIn, 0, 0, 0, 127);
|
||||
if ($transparency === false) {
|
||||
\imagecolortransparent($newIn, $transparency);
|
||||
\imagealphablending($newIn, false);
|
||||
\imagesavealpha($newIn, true);
|
||||
|
||||
\imagecopyresampled(
|
||||
$newIn, $cropped,
|
||||
0, 0,
|
||||
0, 0,
|
||||
$crop['width'], $crop['height'],
|
||||
$srcW, $srcH
|
||||
);
|
||||
|
||||
$srcW = \imagesx($newIn);
|
||||
$srcH = \imagesy($newIn);
|
||||
*/
|
||||
|
||||
$srcW = \imagesx($cropped);
|
||||
$srcH = \imagesy($cropped);
|
||||
|
||||
\imagedestroy($in);
|
||||
|
||||
$in = $cropped;
|
||||
}
|
||||
|
||||
// should resize
|
||||
if ($element->ratio !== 0.0 || $element->width !== 0 || $element->height !== 0) {
|
||||
$ratioX = $element->ratio === 0.0 ? ($element->width - $element->x) / $srcW : $element->ratio;
|
||||
$ratioY = $element->ratio === 0.0 ? ($element->height - $element->y) / $srcH : $element->ratio;
|
||||
|
||||
$newW = (int) ($srcW * $ratioX);
|
||||
$newH = (int) ($srcH * $ratioY);
|
||||
|
||||
$newIn = \imagecreatetruecolor($newW, $newH);
|
||||
if ($newIn === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -151,6 +202,20 @@ class Label
|
|||
$in = $newIn;
|
||||
}
|
||||
|
||||
// should rotate
|
||||
if ($element->rotate !== 0.0) {
|
||||
$rotated = \imagerotate($in, $element->rotate, $transparency);
|
||||
\imagealphablending($rotated, false);
|
||||
\imagesavealpha($rotated, true);
|
||||
|
||||
$srcW = \imagesx($rotated);
|
||||
$srcH = \imagesy($rotated);
|
||||
|
||||
\imagedestroy($in);
|
||||
|
||||
$in = $rotated;
|
||||
}
|
||||
|
||||
$cut = \imagecreatetruecolor($srcW, $srcH);
|
||||
if ($cut === false) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ abstract class ShapeType extends Enum
|
|||
|
||||
public const RECTANGLE = 2;
|
||||
|
||||
public const CIRCLE = 3;
|
||||
public const ELLIPSE = 3;
|
||||
|
||||
public const TRIANGLE = 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
return ['Navigation' => [
|
||||
'Labeling' => '',
|
||||
'List' => '',
|
||||
'Labeling' => 'Etikettierung',
|
||||
'List' => 'Liste',
|
||||
]];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user