Skip to content

Commit

Permalink
上传时及时销毁 InterventionImage 实例以节省内存。
Browse files Browse the repository at this point in the history
  • Loading branch information
0xxb committed Aug 17, 2022
1 parent 2fdb10a commit 289ecff
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Services/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function store(Request $request): Image
$watermarkImage = $this->stickWatermark($file, collect($configs->get(GroupConfigKey::WatermarkConfigs)));
$watermarkImage->save();
$file = new UploadedFile($watermarkImage->basePath(), $file->getClientOriginalName(), $file->getMimeType());
$watermarkImage->destroy();
}

$filename = $this->replacePathname(
Expand Down Expand Up @@ -550,7 +551,7 @@ public function makeThumbnail(Image $image, mixed $data, int $max = 400, bool $f
}

$img->fit($width, $height, fn($constraint) => $constraint->upsize())->encode('png')->save($pathname);

$img->destroy();
} catch (\Throwable $e) {
Utils::e($e, '生成缩略图时出现异常');
}
Expand Down

0 comments on commit 289ecff

Please sign in to comment.