Commit 0f62da28 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Déplacement dans UnicaenApp de la méthode qui Génère une image PNG d'un un texte sur fond gris.

Utilisation pour retourner les messages d'erreurs comme aperçu de la thèse.
parent f7b034f1
Loading
Loading
Loading
Loading
+2 −30
Original line number Diff line number Diff line
@@ -2,10 +2,10 @@

namespace UnicaenLeocarte\Service\Photo;

use UnicaenApp\Util;
use UnicaenLeocarte\Exception\NotFoundException;
use UnicaenLeocarte\Service\Soap\SoapClientAwareInterface;
use UnicaenLeocarte\Service\Soap\SoapClientAwareTrait;
use Zend\Stdlib\Exception\ExtensionNotLoadedException;

/**
 * Guichet pour les opérations concernant les photos.
@@ -155,38 +155,10 @@ class PhotoService implements SoapClientAwareInterface
     */
    private function _createImage($texte)
    {
        if (! extension_loaded('gd')) {
            throw new ExtensionNotLoadedException("L'extension PHP 'gd' doit être activée pour fabriquer l'image");
        }

        $width  = $this->generationPhotoNonAutoriseeConfig['width'];
        $height = $this->generationPhotoNonAutoriseeConfig['height'];

        $tmpImageFilePath = sys_get_temp_dir() . '/' . uniqid('unicaen-leocarte-') . '.png';

        // Create the image
        $img = imagecreatetruecolor($width, $height);

        // Create some colors
        $white = imagecolorallocate($img, 255, 255, 255);
        $grey = imagecolorallocate($img, 245, 245, 245);
        $black = imagecolorallocate($img, 0, 0, 0);
        imagefilledrectangle($img, 0, 0, $width - 1, $height - 1, $grey);

        // Add the text
        $text = utf8_decode($texte);
        $x = 10;
        $y = 20;
        foreach (explode('|', $text) as $part) {
            imagestring($img, 2, $x, $y, $part, $black);
            $y += 15;
        }

        // Using imagepng() results in clearer text compared with imagejpeg()
        imagepng($img, $tmpImageFilePath);
        imagedestroy($img);

        return file_get_contents($tmpImageFilePath);
        return Util::createImageWithText($texte, $width, $height);
    }

    /**