Knp\Bundle\KnpBundlesBundle\Badge\BadgeGenerator::generate PHP Метод

generate() публичный Метод

Generate Badge images
public generate ( Bundle $bundle )
$bundle Knp\Bundle\KnpBundlesBundle\Entity\Bundle
    public function generate(Bundle $bundle)
    {
        // Open bg badge image
        $image = $this->imagine->open($this->getResourceDir() . '/images/' . $this->type[self::LONG]);
        $imageShort = $this->imagine->open($this->getResourceDir() . '/images/' . $this->type[self::SHORT]);
        // Bundle Title
        $bundleName = $this->shorten($bundle->getName(), 16);
        $image->draw()->text($bundleName, $this->setFont($this->imagine, $this->font, 14, '085066'), new Point(75, 10));
        // Score points
        $score = $bundle->getScore() ?: 'N/A';
        $image->draw()->text($score, $this->setFont($this->imagine, $this->font, 18), $this->getPositionByType($score, self::LONG));
        $imageShort->draw()->text($score, $this->setFont($this->imagine, $this->font, 16), $this->getPositionByType($score, self::SHORT));
        // Recommend
        $recommenders = $bundle->getNbRecommenders();
        if ($recommenders) {
            $recommendationsText = $recommenders . ' recommendations';
        } else {
            $recommendationsText = 'No recommendations';
        }
        $image->draw()->text($recommendationsText, $this->setFont($this->imagine, $this->font, 9), new Point(92, 33));
        // Check or create dir for generated badges
        $this->createBadgesDir();
        // Remove existing badge
        $this->filesystem->remove($this->getBadgeFile($bundle));
        $this->filesystem->remove($this->getBadgeFile($bundle, self::SHORT));
        // Save badge
        $image->save($this->getBadgeFile($bundle));
        $imageShort->save($this->getBadgeFile($bundle, self::SHORT));
        // Set write permission for father files update
        chmod($this->getBadgeFile($bundle), 0777);
        chmod($this->getBadgeFile($bundle, self::SHORT), 0777);
    }