Joli\GifExceptionBundle\Command\GifOptimizerCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    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)));
        }
    }