$content =
ob_get_contents();
if (!\
is_string($content)) { throw new RuntimeException('Could not open image'
);
} ob_end_clean();
$this->mediaService->
write($destination,
$content);
} private function optimizeImage(string
$destination): void
{ $tmpFilename =
$this->
downloadImage($destination);
try { $this->optimizerService->
optimize($tmpFilename);
$this->
uploadImage($destination,
$tmpFilename);
} catch (OptimizerNotFoundException
$exception) { // empty catch intended since no optimizer is available
} finally { unlink($tmpFilename);
} }