Skip to content

Instantly share code, notes, and snippets.

@lyrixx
Created November 20, 2015 18:42
Show Gist options
  • Save lyrixx/44c737e5096e69ea9305 to your computer and use it in GitHub Desktop.
Save lyrixx/44c737e5096e69ea9305 to your computer and use it in GitHub Desktop.
Barcode
<?php
<<<CONFIG
packages:
- "zendframework/zend-barcode: ^2.5"
- "symfony/console: ^2.7"
CONFIG;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Zend\Barcode\Barcode;
use Zend\ServiceManager\Config;
(new Application())
->register('barcode')
->setDescription('generate a bar code')
->addArgument('what', InputArgument::REQUIRED, 'What to print as bar code')
->setCode(function (InputInterface $input, OutputInterface $output) {
$what = $input->getArgument('what');
$file = $what.'.png';
if (file_exists($file)) {
$question = new ConfirmationQuestion("The files $file already exists. Override it? [Yn] ");
$helper = new QuestionHelper();
if (!$helper->ask($input, $output, $question)) {
return 0;
}
}
$image = Barcode::factory('code39', 'image', ['text' => $what], [])->draw();
imagepng($image, $file);
$output->writeln("<comment>$file</> generated");
})
->getApplication()
->run()
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment