Skip to content

Commit 6a05042

Browse files
reloxx13andi34
authored andcommitted
initial config would rotate by 0 degree, resulting in a black image
Change-Id: Ia639c1f188b9174a3accb343bafc2e6eb6de9a81
1 parent fb9147c commit 6a05042

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

api/applyEffects.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,18 @@
150150
}
151151
}
152152

153-
if ($config['picture']['rotation'] !== '0') {
153+
if ((int)$config['picture']['rotation'] !== 0) {
154154
$imageResource = $imageHandler->rotateResizeImage(
155155
image: $imageResource,
156-
degrees: $config['picture']['rotation']
156+
degrees: (int)$config['picture']['rotation'],
157157
);
158158
if (!$imageResource instanceof \GdImage) {
159159
throw new \Exception('Error resizing resource.');
160160
}
161161
}
162162

163163
// Apply rembg
164-
list($imageHandler, $imageResource) = Rembg::process($imageHandler, $vars, $config['rembg'], $imageResource);
164+
[$imageHandler, $imageResource] = Rembg::process($imageHandler, $vars, $config['rembg'], $imageResource);
165165
if ($config['picture']['polaroid_effect']) {
166166
$imageHandler->polaroidRotation = $config['picture']['polaroid_rotation'];
167167
$imageResource = $imageHandler->effectPolaroid($imageResource);

api/chromakeying/save.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@
121121
}
122122
}
123123

124-
if ($config['picture']['rotation'] !== '0') {
124+
if ((int)$config['picture']['rotation'] !== 0) {
125125
$imageResource = $imageHandler->rotateResizeImage(
126126
image: $imageResource,
127-
degrees: $config['picture']['rotation']
127+
degrees: (int)$config['picture']['rotation'],
128128
);
129129
if (!$imageResource instanceof \GdImage) {
130130
throw new \Exception('Error resizing resource.');

src/Image.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ public function saveJpeg(GdImage $sourceResource, string $destination): bool
438438
*/
439439
public function rotateResizeImage(GdImage $image, int $degrees, string $bgColor = '#ffffff', bool $useTransparentBackground = false): GdImage|false
440440
{
441+
if ($degrees % 360 === 0) {
442+
// No rotation needed for 0, 360, -360, etc.
443+
return $image;
444+
}
445+
441446
$new = $image;
442447
try {
443448
// simple rotate if possible and ignore changed dimensions (doesn't need to care about background color)
@@ -447,6 +452,8 @@ public function rotateResizeImage(GdImage $image, int $degrees, string $bgColor
447452
if (!$new) {
448453
throw new \Exception('Cannot rotate image.');
449454
}
455+
// without, 0 degree rotation would loose alpha blending, results in black image
456+
imagealphablending($new, true);
450457
} else {
451458
$old_width = imagesx($image);
452459
$old_height = imagesy($image);
@@ -465,7 +472,7 @@ public function rotateResizeImage(GdImage $image, int $degrees, string $bgColor
465472
$background = imagecolorallocatealpha($new, 0, 0, 0, 127);
466473
} else {
467474
$colorComponents = self::getColorComponents($bgColor);
468-
list($bg_r, $bg_g, $bg_b, $bg_a) = $colorComponents;
475+
[$bg_r, $bg_g, $bg_b, $bg_a] = $colorComponents;
469476
// color background as defined
470477
$background = imagecolorallocatealpha($new, $bg_r, $bg_g, $bg_b, $bg_a);
471478
}

test/photo.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
}
4343
if (class_exists('Photobooth\Processor\ImageProcessor')) {
4444
$processor = new ImageProcessor($imageHandler, $logger, $database, $vars, $config);
45-
}
46-
if ($processor !== null && $processor instanceof ImageProcessor && method_exists($processor, 'preImageProcessing')) {
47-
[$imageHandler, $vars, $config, $imageResource] = $processor->preImageProcessing($imageHandler, $vars, $config, $imageResource);
45+
if (method_exists($processor, 'preImageProcessing')) {
46+
[$imageHandler, $vars, $config, $imageResource] = $processor->preImageProcessing($imageHandler, $vars, $config, $imageResource);
47+
}
4848
}
4949
$imageHandler->framePath = PathUtility::getPublicPath($config['picture']['frame']);
5050

@@ -73,10 +73,10 @@
7373
}
7474
}
7575

76-
if ($config['picture']['rotation'] !== '0') {
76+
if ((int)$config['picture']['rotation'] !== 0) {
7777
$imageResource = $imageHandler->rotateResizeImage(
7878
image: $imageResource,
79-
degrees: $config['picture']['rotation']
79+
degrees: (int)$config['picture']['rotation'],
8080
);
8181
if (!$imageResource) {
8282
throw new \Exception('Error resizing resource.');

0 commit comments

Comments
 (0)