Skip to content

Commit 3494fc8

Browse files
committed
fix: Doc minification - change placeholder to deepl text
1 parent 7cf7182 commit 3494fc8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/DocumentMinifier.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ private function extractZipTo(string $zippedDocumentPath, string $extractionDir,
265265
private function exportMediaToMediaDirAndReplace(string $inputDirectory, string $mediaDirectory)
266266
{
267267
$imageData = array();
268-
$placeholderImage = imagecreatetruecolor(1, 1);
269268
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($inputDirectory));
270269
foreach ($iterator as $file) {
271270
if ($file->isFile() && array_key_exists($file->getExtension(), DocumentMinifier::SUPPORTED_MEDIA_FORMATS)) {
@@ -285,17 +284,25 @@ private function exportMediaToMediaDirAndReplace(string $inputDirectory, string
285284
"Exception when backing up document media: Failed to move $curFilePath to $mediaPath."
286285
);
287286
}
288-
if (!imagepng($placeholderImage, $curFilePath)) {
287+
if (!$this->storePlaceholderAt($curFilePath)) {
289288
throw new DocumentMinificationException(
290-
"Exception when minifying document: Failed to store replacement image at $curFilePath."
289+
"Exception when minifying document: Failed to store replacement data at $curFilePath."
291290
);
292291
}
293292
}
294293
}
295-
imagedestroy($placeholderImage);
296294
return $imageData;
297295
}
298296

297+
private function storePlaceholderAt(string $filename): bool
298+
{
299+
$putContentsResp = file_put_contents($filename, 'DeepL Media Placeholder');
300+
if ($putContentsResp === false) {
301+
return false;
302+
}
303+
return true;
304+
}
305+
299306
private function replaceImagesInDir(string $directory, string $mediaDirectory)
300307
{
301308
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($mediaDirectory));

0 commit comments

Comments
 (0)