Ankündigung

Einklappen
Keine Ankündigung bisher.

imagepng ändert unerklärlicherweise Hintergrundfarbe

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • imagepng ändert unerklärlicherweise Hintergrundfarbe

    Hallo Community,

    ich bin seit Tagen am verzweifeln, wieso der Tranparente Hintergrund bei mit am ende des Scripts schwarz wird, kann man da einer bitte helfen...

    PHP-Code:
    <?php

    function watermarkImage ($SourceFile$WaterMarkText$DestinationFile='') {
       list(
    $width$height) = getimagesize($SourceFile);
       
    $image_p imagecreatetruecolor($width$height);
       
    //$image = imagecreatefromjpeg($SourceFile);
       
    $image imagecreatefrompng($SourceFile);
       
    imagecopyresampled($image_p$image0000$width$height$width$height);
       
    $black imagecolorallocate($image_p000);
       
    $font 'arialbd.ttf';
       
    $font_size 12;
       
    imagettftext($image_p$font_size08216$black$font$WaterMarkText);
       if (
    $DestinationFile !== '') {
          
    //imagejpeg ($image_p, $DestinationFile, 100);
          
    imagepng ($image_p$DestinationFile5);
       } else {
          
    //header('Content-Type: image/jpeg');
          
    header('Content-Type: image/png');
          
    //imagejpeg($image_p, null, 100);
          
    imagepng($image_pnull5);
       };
       
    imagedestroy($image);
       
    imagedestroy($image_p);
    };

    function 
    watermarkImage_dt ($SourceFile_dt$WaterMarkText_dt$DestinationFile_dt='') {
       list(
    $width$height) = getimagesize($SourceFile_dt);
       
    $image_p_dt imagecreatetruecolor($width$height);
       
    //$image_dt = imagecreatefromjpeg($SourceFile_dt);
       
    $image_dt imagecreatefrompng($SourceFile_dt);
       
    imagecopyresampled($image_p_dt$image_dt0000$width$height$width$height);
       
    $black imagecolorallocate($image_p_dt2002000);
       
    $font 'arial.ttf';
       
    $font_size 10;
       
    imagettftext($image_p_dt$font_size09438$black$font$WaterMarkText_dt);
       if (
    $DestinationFile_dt !== '') {
         
    // imagejpeg ($image_p_dt, $DestinationFile_dt, 100);
          
    imagepng ($image_p_dt$DestinationFile_dt5);
       } else {
          
    //header('Content-Type: image/jpeg');
          
    header('Content-Type: image/png');
          
    //imagejpeg($image_p_dt, null, 100);
          
    imagepng($image_p_dtnull5);
       };
       
    imagedestroy($image_dt);
       
    imagedestroy($image_p_dt);
    };

    ?>
    <form action='' method='post'>
    Spanischer Posten: <input name='span' maxlength="21"/><br/>
    Deutscher Posten: <input name='deut'  maxlength="25"/> 
    <input type='submit' />
    </form>





    <?php
    $span
    =$_POST["span"];
    $deut=$_POST["deut"];



    /*
    $SourceFile = 'siegel_roh.jpg';
    $DestinationFile = 'fertig.jpg';*/
    $SourceFile 'siegel_roh.png';
    $DestinationFile 'fertig.png';
    $WaterMarkText $span;
    $SourceFile_dt $DestinationFile;
    $DestinationFile_dt $DestinationFile;
    $WaterMarkText_dt "(".$deut.")";
    watermarkImage ($SourceFile$WaterMarkText$DestinationFile);
    watermarkImage_dt ($SourceFile_dt$WaterMarkText_dt$DestinationFile_dt);


    echo 
    "fertig";
    ?>

  • #2
    Kommt ganz darauf an, was du als Watermark lädst. PNG ist nicht gleich PNG. Je nach dem wie du es abgespeichert hast kann sich die Bittiefe, Alpha-Blending etc im PNG unterscheiden.

    Man findet übrigens im MANUAL als ERSTEN Kommentar
    If you're trying to load a translucent png-24 image but are finding an absence of transparency (like it's black), you need to enable alpha channel AND save the setting. I'm new to GD and it took me almost two hours to figure this out.

    PHP-Code:
    <?php
    $imgPng 
    imageCreateFromPng($strImagePath);
    imageAlphaBlending($imgPngtrue);
    imageSaveAlpha($imgPngtrue);

    /* Output image to browser */
    header("Content-type: image/png");
    imagePng($imgPng); 
    ?>

    Kommentar


    • #3
      Na das "Watermark" ist ein TExtstring, welcher auf das Bild stehen soll.

      Kommentar


      • #4
        und auch mit dem alphakanal bleibt es schwarz

        Kommentar

        Lädt...
        X