Fix: Global namespace for GD and multi-step Docker build
Browse files
_hf_deploy_medilis
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
Subproject commit
|
|
|
|
| 1 |
+
Subproject commit 3ec0379bd80108f98b0a9b4ebc9f0333903db154
|
app/Services/FreepikAssetRemixService.php
CHANGED
|
@@ -300,39 +300,39 @@ private function optimizeReferenceImage(string $binary): string
|
|
| 300 |
return $binary;
|
| 301 |
}
|
| 302 |
|
| 303 |
-
if (! function_exists('imagecreatefromstring')) {
|
| 304 |
throw new RuntimeException('Reference image lebih besar dari 10MB dan GD tidak tersedia untuk kompres otomatis.');
|
| 305 |
}
|
| 306 |
|
| 307 |
-
$image = @imagecreatefromstring($binary);
|
| 308 |
if (! $image) {
|
| 309 |
throw new RuntimeException('Reference image terlalu besar dan gagal dikompres untuk Freepik edit.');
|
| 310 |
}
|
| 311 |
|
| 312 |
try {
|
| 313 |
-
$width = imagesx($image);
|
| 314 |
-
$height = imagesy($image);
|
| 315 |
$longestEdge = max($width, $height, 1);
|
| 316 |
$scale = min(1, 1800 / $longestEdge);
|
| 317 |
$targetWidth = max(1, (int) round($width * $scale));
|
| 318 |
$targetHeight = max(1, (int) round($height * $scale));
|
| 319 |
|
| 320 |
-
$canvas = imagecreatetruecolor($targetWidth, $targetHeight);
|
| 321 |
if (! $canvas) {
|
| 322 |
throw new RuntimeException('Gagal membuat canvas kompresi untuk reference image.');
|
| 323 |
}
|
| 324 |
|
| 325 |
try {
|
| 326 |
-
$background = imagecolorallocate($canvas, 255, 255, 255);
|
| 327 |
-
imagefill($canvas, 0, 0, $background);
|
| 328 |
-
imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
|
| 329 |
|
| 330 |
$quality = 88;
|
| 331 |
$encoded = '';
|
| 332 |
|
| 333 |
do {
|
| 334 |
ob_start();
|
| 335 |
-
imagejpeg($canvas, null, $quality);
|
| 336 |
$encoded = (string) ob_get_clean();
|
| 337 |
$quality -= 8;
|
| 338 |
} while ($encoded !== '' && strlen($encoded) > $maxBytes && $quality >= 56);
|
|
@@ -343,10 +343,10 @@ private function optimizeReferenceImage(string $binary): string
|
|
| 343 |
|
| 344 |
return $encoded;
|
| 345 |
} finally {
|
| 346 |
-
imagedestroy($canvas);
|
| 347 |
}
|
| 348 |
} finally {
|
| 349 |
-
imagedestroy($image);
|
| 350 |
}
|
| 351 |
}
|
| 352 |
|
|
|
|
| 300 |
return $binary;
|
| 301 |
}
|
| 302 |
|
| 303 |
+
if (! function_exists('\imagecreatefromstring')) {
|
| 304 |
throw new RuntimeException('Reference image lebih besar dari 10MB dan GD tidak tersedia untuk kompres otomatis.');
|
| 305 |
}
|
| 306 |
|
| 307 |
+
$image = @\imagecreatefromstring($binary);
|
| 308 |
if (! $image) {
|
| 309 |
throw new RuntimeException('Reference image terlalu besar dan gagal dikompres untuk Freepik edit.');
|
| 310 |
}
|
| 311 |
|
| 312 |
try {
|
| 313 |
+
$width = \imagesx($image);
|
| 314 |
+
$height = \imagesy($image);
|
| 315 |
$longestEdge = max($width, $height, 1);
|
| 316 |
$scale = min(1, 1800 / $longestEdge);
|
| 317 |
$targetWidth = max(1, (int) round($width * $scale));
|
| 318 |
$targetHeight = max(1, (int) round($height * $scale));
|
| 319 |
|
| 320 |
+
$canvas = \imagecreatetruecolor($targetWidth, $targetHeight);
|
| 321 |
if (! $canvas) {
|
| 322 |
throw new RuntimeException('Gagal membuat canvas kompresi untuk reference image.');
|
| 323 |
}
|
| 324 |
|
| 325 |
try {
|
| 326 |
+
$background = \imagecolorallocate($canvas, 255, 255, 255);
|
| 327 |
+
\imagefill($canvas, 0, 0, $background);
|
| 328 |
+
\imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
|
| 329 |
|
| 330 |
$quality = 88;
|
| 331 |
$encoded = '';
|
| 332 |
|
| 333 |
do {
|
| 334 |
ob_start();
|
| 335 |
+
\imagejpeg($canvas, null, $quality);
|
| 336 |
$encoded = (string) ob_get_clean();
|
| 337 |
$quality -= 8;
|
| 338 |
} while ($encoded !== '' && strlen($encoded) > $maxBytes && $quality >= 56);
|
|
|
|
| 343 |
|
| 344 |
return $encoded;
|
| 345 |
} finally {
|
| 346 |
+
\imagedestroy($canvas);
|
| 347 |
}
|
| 348 |
} finally {
|
| 349 |
+
\imagedestroy($image);
|
| 350 |
}
|
| 351 |
}
|
| 352 |
|
app/Services/MotionVideoService.php
CHANGED
|
@@ -101,15 +101,15 @@ private function normalizeImageFrame(string $imageUrl, string $workingDir): stri
|
|
| 101 |
throw new RuntimeException('URL gambar mengembalikan halaman HTML bukan file gambar. Coba generate ulang gambar sumbernya.');
|
| 102 |
}
|
| 103 |
|
| 104 |
-
$resource = @imagecreatefromstring($binary);
|
| 105 |
|
| 106 |
if ($resource === false) {
|
| 107 |
// Try format-specific fallbacks
|
| 108 |
$tmpFile = tempnam(sys_get_temp_dir(), 'mvframe_');
|
| 109 |
file_put_contents($tmpFile, $binary);
|
| 110 |
-
$resource = @imagecreatefrompng($tmpFile) ?:
|
| 111 |
-
(@imagecreatefromjpeg($tmpFile) ?:
|
| 112 |
-
(@imagecreatefromwebp($tmpFile) ?: false));
|
| 113 |
@unlink($tmpFile);
|
| 114 |
}
|
| 115 |
|
|
@@ -121,12 +121,12 @@ private function normalizeImageFrame(string $imageUrl, string $workingDir): stri
|
|
| 121 |
}
|
| 122 |
|
| 123 |
$framePath = $workingDir.'/frame_'.now()->format('Ymd_His').'_'.Str::lower(Str::random(8)).'.jpg';
|
| 124 |
-
if (! @imagejpeg($resource, $framePath, 92)) {
|
| 125 |
-
imagedestroy($resource);
|
| 126 |
throw new RuntimeException('Gagal menyimpan frame sementara untuk video.');
|
| 127 |
}
|
| 128 |
|
| 129 |
-
imagedestroy($resource);
|
| 130 |
|
| 131 |
return $framePath;
|
| 132 |
}
|
|
|
|
| 101 |
throw new RuntimeException('URL gambar mengembalikan halaman HTML bukan file gambar. Coba generate ulang gambar sumbernya.');
|
| 102 |
}
|
| 103 |
|
| 104 |
+
$resource = @\imagecreatefromstring($binary);
|
| 105 |
|
| 106 |
if ($resource === false) {
|
| 107 |
// Try format-specific fallbacks
|
| 108 |
$tmpFile = tempnam(sys_get_temp_dir(), 'mvframe_');
|
| 109 |
file_put_contents($tmpFile, $binary);
|
| 110 |
+
$resource = @\imagecreatefrompng($tmpFile) ?:
|
| 111 |
+
(@\imagecreatefromjpeg($tmpFile) ?:
|
| 112 |
+
(@\imagecreatefromwebp($tmpFile) ?: false));
|
| 113 |
@unlink($tmpFile);
|
| 114 |
}
|
| 115 |
|
|
|
|
| 121 |
}
|
| 122 |
|
| 123 |
$framePath = $workingDir.'/frame_'.now()->format('Ymd_His').'_'.Str::lower(Str::random(8)).'.jpg';
|
| 124 |
+
if (! @\imagejpeg($resource, $framePath, 92)) {
|
| 125 |
+
\imagedestroy($resource);
|
| 126 |
throw new RuntimeException('Gagal menyimpan frame sementara untuk video.');
|
| 127 |
}
|
| 128 |
|
| 129 |
+
\imagedestroy($resource);
|
| 130 |
|
| 131 |
return $framePath;
|
| 132 |
}
|