Commit 012bdf81 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

[FIX] Balises <img> des logos/signatures dont la src est le contenu binaire :...

[FIX] Balises <img> des logos/signatures dont la src est le contenu binaire : le format était systématiquement image/png ce qui posait problème si l'image était d'un autre format.
parent c4876a77
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -446,7 +446,7 @@ class FichierTheseController extends AbstractController
        /** @var \Laminas\Http\Response $response */
        $response = $this->getResponse();

        return $this->fichierTheseService->createResponseForFileContent($response, $content);
        return $this->fichierTheseService->createResponseForFileContent($response, $content, "image/png");
    }

    /**
+5 −8
Original line number Diff line number Diff line
@@ -420,12 +420,10 @@ class FichierTheseService extends BaseService
     * @param string $inputFilePath
     * @return string Contenu binaire du fichier PNG généré
     * @throws LogicException Format de fichier incorrect
     *
     * @deprecated Appeler directement FileService::generateFirstPagePreview()
     */
    public function generateFirstPagePreview($inputFilePath)
    public function generateFirstPagePreview(string $inputFilePath): string
    {
        return $this->fileService->generateFirstPagePreview($inputFilePath);
        return $this->fileService->generateFirstPagePreviewPngImageFromPdf($inputFilePath);
    }

    /**
@@ -450,14 +448,13 @@ class FichierTheseService extends BaseService
    /**
     * @param Response $response
     * @param string $fileContent
     * @param string $mimeType Ex : "image/png"
     * @param int|null $cacheMaxAge En secondes, ex: 60*60*24 = 86400 s = 1 jour
     * @return Response
     *
     * @deprecated Appeler directement FileService::createResponseForFileContent()
     */
    public function createResponseForFileContent(Response $response, $fileContent, $cacheMaxAge = null)
    public function createResponseForFileContent(Response $response, string $fileContent, string $mimeType, ?int $cacheMaxAge = null): Response
    {
        return $this->fileService->createResponseForFileContent($response, $fileContent, $cacheMaxAge);
        return $this->fileService->createResponseForFileContent($response, $fileContent, $mimeType, $cacheMaxAge);
    }

    /**
+5 −6
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ class FileService
     * @param string $inputFilePath
     * @return string Contenu binaire du fichier PNG généré
     */
    public function generateFirstPagePreview($inputFilePath)
    public function generateFirstPagePreviewPngImageFromPdf(string $inputFilePath): string
    {
        if (mime_content_type($inputFilePath) !== Fichier::MIME_TYPE_PDF) {
            return \UnicaenApp\Util::createImageWithText("Erreur: Seul le format |de fichier PDF est accepté", 200, 100);
@@ -182,9 +182,7 @@ class FileService
                "Erreur rencontrée lors de la création de l'aperçu", null, $ie);
        }

        $content = file_get_contents($outputFilePath);

        return $content;
        return file_get_contents($outputFilePath);
    }

    public function computeDirectoryPathForInformation() {
@@ -195,17 +193,18 @@ class FileService
    /**
     * @param Response $response
     * @param string $fileContent
     * @param string $mimeType
     * @param int|null $cacheMaxAge En secondes, ex: 60*60*24 = 86400 s = 1 jour
     * @return Response
     */
    public function createResponseForFileContent(Response $response, $fileContent, $cacheMaxAge = null)
    public function createResponseForFileContent(Response $response, string $fileContent, string $mimeType, ?int $cacheMaxAge = null): Response
    {
        $response->setContent($fileContent);

        $headers = $response->getHeaders();
        $headers
            ->addHeaderLine('Content-Transfer-Encoding', "binary")
            ->addHeaderLine('Content-Type', "image/png")
            ->addHeaderLine('Content-Type', $mimeType)
            ->addHeaderLine('Content-length', strlen($fileContent));

        if ($cacheMaxAge === null) {
+2 −2
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ class StructureSubstitHelper extends AbstractHelper
        $texte .= '<div id="logo-div" class="float-end ">';
        if ($structurestructureConcrete->getCheminLogo() !== null)
            $texte .= '<input champ="logo" id="logo_' . $structurestructureConcrete->getSigle() . '" type="radio" name="logo" /> &nbsp; ';
        $texte .= '<img class="current" style="max-width: 125px; max-height: 125px; border: 1px solid black; background-color: white;" src="data:image/png;base64,' . base64_encode($logoContent) . '"/>';
        $texte .= '<img class="current" style="max-width: 125px; max-height: 125px; border: 1px solid black; background-color: white;" src="data:image/*;base64,' . base64_encode($logoContent) . '"/>';
        $texte .= '<input class="path" type="hidden" champ="cheminLogo" name="cheminLogo" value="' . $structurestructureConcrete->getStructure()->getCheminLogo() . '"/>';
        $texte .= '</div>';
        $texte .= '</div>';
@@ -86,7 +86,7 @@ class StructureSubstitHelper extends AbstractHelper
        $texte .= '    <div class="card-body">';
        $texte .= "<div id='logo-div' class='float-end'>";
        $texte .= "<input type='hidden' name='cible[cheminLogo]' id='logo' value='" . $structure->getCheminLogo() . "'/>";
        $texte .= "<img id='logo_tmp' style='max-width: 125px; max-height: 125px; border: 1px solid black; background-color: white;' src='data:image/png;base64," . base64_encode($logoContent) . "'/>";
        $texte .= "<img id='logo_tmp' style='max-width: 125px; max-height: 125px; border: 1px solid black; background-color: white;' src='data:image/*;base64," . base64_encode($logoContent) . "'/>";
        $texte .= "</div>";

        $texte .= "<br/>";
+1 −1
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ $structure = $ecole->getStructure();
                    <dt>Logo :</dt>
                    <dd>
                        <img id="logo" style="max-width: 200px; max-height: 200px; background-color: white;"
                             src="data:image/png;base64,<?php echo base64_encode($logoContent); ?>"/>
                             src="data:image/*;base64,<?php echo base64_encode($logoContent); ?>"/>
                    </dd>
                </dl>
            </div>
Loading