/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $imageDir = $input->getArgument('image_dir');
     if (!is_dir($imageDir)) {
         throw new \RuntimeException($imageDir . ' is not a valid directory');
     }
     $pattern = $imageDir . '/*/*.gif';
     foreach (glob($pattern) as $path) {
         $realPath = realpath($path);
         $originalFileSize = filesize($realPath);
         $output->writeln(sprintf('<info>Optimizing image: %s</info>', $realPath));
         $output->writeln(sprintf('<comment>Before: %s</comment>', $this->formatBytes($originalFileSize)));
         $this->optimizer->optimize($realPath);
         // File size information is cached, so make sure we clear this to get the file save difference.
         clearstatcache(true, $realPath);
         $optimizedFileSize = filesize($realPath);
         $output->writeln(sprintf('<comment>After: %s</comment>', $this->formatBytes($optimizedFileSize)));
         $percentage = 100 - $optimizedFileSize / $originalFileSize * 100;
         $output->writeln(sprintf('<comment>Saving: %s%%</comment>', round($percentage)));
     }
 }
 private function unwrap(Optimizer $optimizer)
 {
     return $optimizer instanceof SuppressErrorOptimizer ? $optimizer->unwrap() : $optimizer;
 }