mirror of
https://github.com/Karaka-Management/oms-Labeling.git
synced 2026-02-15 08:58: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 $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 $x2 = 0;
|
||||||
|
|
||||||
|
public int $y1 = 0;
|
||||||
|
|
||||||
public int $y2 = 0;
|
public int $y2 = 0;
|
||||||
|
|
||||||
public string $src = '';
|
public string $src = '';
|
||||||
|
|
|
||||||
103
Models/Label.php
103
Models/Label.php
|
|
@ -67,8 +67,7 @@ class Label
|
||||||
|
|
||||||
// @todo: replace int type with enum
|
// @todo: replace int type with enum
|
||||||
if ($element instanceof Shape) {
|
if ($element instanceof Shape) {
|
||||||
if ($element->type === 1) {
|
if ($element->type === ShapeType::LINE) {
|
||||||
// Line
|
|
||||||
if ($element->borderThickness === 1) {
|
if ($element->borderThickness === 1) {
|
||||||
\imageline($im, $element->x, $element->y, $element->x2, $element->y2, $color);
|
\imageline($im, $element->x, $element->y, $element->x2, $element->y2, $color);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -79,8 +78,7 @@ class Label
|
||||||
$color
|
$color
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} elseif ($element->type === 2) {
|
} elseif ($element->type === ShapeType::RECTANGLE) {
|
||||||
// Rectangle
|
|
||||||
\imagefilledrectangle(
|
\imagefilledrectangle(
|
||||||
$im,
|
$im,
|
||||||
$element->x, $element->y,
|
$element->x, $element->y,
|
||||||
|
|
@ -96,9 +94,23 @@ class Label
|
||||||
$bg
|
$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) {
|
} elseif ($element instanceof Text) {
|
||||||
\imagettftext($im, $element->size, 0, $element->x, $element->y, $color, $element->font, $element->text);
|
\imagettftext($im, $element->size, 0, $element->x, $element->y, $color, $element->font, $element->text);
|
||||||
} elseif ($element instanceof Image) {
|
} elseif ($element instanceof Image) {
|
||||||
|
|
@ -107,27 +119,66 @@ class Label
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\imagealphablending($in, false);
|
||||||
|
\imagesavealpha($in, true);
|
||||||
|
|
||||||
|
$transparency = \imagecolorallocatealpha($in, 0, 0, 0, 127);
|
||||||
|
if ($transparency === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$srcW = \imagesx($in);
|
$srcW = \imagesx($in);
|
||||||
$srcH = \imagesy($in);
|
$srcH = \imagesy($in);
|
||||||
|
|
||||||
// should resize
|
// should crop
|
||||||
// @todo: impl. skewing
|
if ($element->x1 !== 0 || $element->x2 !== 0 || $element->y1 !== 0 || $element->y2 !== 0) {
|
||||||
if ($element->ratio !== 0.0 || $element->x2 !== 0 || $element->y2 !== 0) {
|
$cropped = \imagecrop($in, [
|
||||||
$ratio = $element->ratio;
|
'x' => $element->x1,
|
||||||
if ($ratio === 0.0) {
|
'y' => $element->y1,
|
||||||
$ratio = ($element->x2 - $element->x) / $srcW;
|
'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($crop['width'], $crop['height']);
|
||||||
|
|
||||||
$newIn = \imagecreatetruecolor($newW, $newH);
|
|
||||||
if ($newIn === false) {
|
if ($newIn === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$transparency = \imagecolorallocatealpha($newIn, 0, 0, 0, 127);
|
\imagecolortransparent($newIn, $transparency);
|
||||||
if ($transparency === false) {
|
\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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,6 +202,20 @@ class Label
|
||||||
$in = $newIn;
|
$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);
|
$cut = \imagecreatetruecolor($srcW, $srcH);
|
||||||
if ($cut === false) {
|
if ($cut === false) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ abstract class ShapeType extends Enum
|
||||||
|
|
||||||
public const RECTANGLE = 2;
|
public const RECTANGLE = 2;
|
||||||
|
|
||||||
public const CIRCLE = 3;
|
public const ELLIPSE = 3;
|
||||||
|
|
||||||
public const TRIANGLE = 4;
|
public const TRIANGLE = 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,6 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
return ['Navigation' => [
|
return ['Navigation' => [
|
||||||
'Labeling' => '',
|
'Labeling' => 'Etikettierung',
|
||||||
'List' => '',
|
'List' => 'Liste',
|
||||||
]];
|
]];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user