Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] Image: Speichern des Alpha-Kanales

Einklappen

Neue Werbung 2019

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

  • [Erledigt] Image: Speichern des Alpha-Kanales

    Mit diesem Code:
    PHP-Code:
    <?php
    $gesamt
    =imagecreatetruecolor(256,512);//erzeuge gesamt-bild

    imagefilledrectangle($gesamt,100,100,200,200,imagecolorallocate($gesamt,255,0,0));

    $eins=imagecreatefrompng("1.png");//lade erstes bild
    $zwei=imagecreatefrompng("2.png");//lade zweites bild

    imagecopy  ($gesamt,$eins,0,0,0,0,256,256);//kopiere erstes bild
    imagecopy  ($gesamt,$zwei,0,256,0,0,256,256);//und das zweite bild darunter

    imagesavealpha($gesamt,true);//alpha-kanal soll auch gespeichert werden!
    imagepng($gesamt"gesamt.png",9);//speichern des bildes
    ?>
    sollen die Bilder 1.png und 2.png

    zusammengefügt werden. Die beiden Bilder sind großteils transparent mit etwas farbe dazwischen. Mit [MAN]imagesavealpha[/MAN] soll bewirkt werden, dass der Alphakanal gespeichert wird. das ist aber nicht der Fall:


    wie kann ich das machen, das der alphakanal doch gespeichert wird?

  • #2
    PHP: imagecopy - Manual

    .. da müsstest du in den User Notes was finden über Hintegrundtransparenz...

    ... das führt dich zu:

    PHP: imagealphablending - Manual

    Und da steht in den User Notes folgendes:

    If you are trying to copy a transparant image on to another image, you might assume that you should apply the ImageAlphaBlending function to the image that has the transparancy, the source image. In reality, you must apply the ImageAlphaBlending function to the destination image. Basically it's saying, "make the specified image respect transparancy".

    Here's a real world example. Suppose you want to put your logo on the upper left corner of a photograph. Your logo is a PNG with transparancy, and the photo is a JPEG. Here's what you would do:

    <?php
    $photoImage = ImageCreateFromJPEG('photo.jpg');
    ImageAlphaBlending($photoImage, true);

    $logoImage = ImageCreateFromPNG('logo.png');
    $logoW = ImageSX($logoImage);
    $logoH = ImageSY($logoImage);

    ImageCopy($photoImage, $logoImage, 0, 0, 0, 0, $logoW, $logoH);

    ImageJPEG($photoImage); // output to browser

    ImageDestroy($photoImage);
    ImageDestroy($logoImage);
    ?>
    Mit freundlichen Grüßen

    Ihr Google und C&P Service
    "Alles im Universum funktioniert, wenn du nur weißt wie du es anwenden musst".

    Kommentar


    • #3
      nein, das ist ja nicht das problem.

      die transparenten bilder werden ja richtig kopiert(dafür habe ich ja dieses sinnlose rechteck gezeichnnet). Nur beim Speichern geht der Alphakanal verloren.

      Kommentar


      • #4
        Ich habe jetzt eine lösung gefunden: mit gimp mache ich ein 256*512 großes bild, das nur transparent ist. dann erzeuge ich $gesamt nicht, sondern lade es mit
        PHP-Code:
        $gesamt=imagecreatefrompng("empty.png"); 
        Das ist natürlich nicht optimal, da ich ja immer verschieden große bilder erzeugen will.
        da muss es doch irgendeine möglichkeit geben, den hintergrund transparent zu färben.

        Kommentar


        • #5
          jetzt habe ich eine bessere Lösung gefunden:
          PHP-Code:
          <?php

          $gesamt
          =imagecreatetruecolor(256,512);//erzeuge gesamt-bild

          ImageAlphaBlending($gesamttrue);
          $trans_colour imagecolorallocatealpha($gesamt000127);//THAT'S IT!
          imagefill($gesamt00$trans_colour);//THAT'S IT!

          imagefilledrectangle($gesamt,100,100,200,200,imagecolorallocate($gesamt,255,0,0));

          $eins=imagecreatefrompng("1.png");//lade erstes bild
          $zwei=imagecreatefrompng("2.png");//lade zweites bild

          imagecopy  ($gesamt,$eins,0,0,0,0,256,256);//kopiere erstes bild
          imagecopy  ($gesamt,$zwei,0,256,0,0,256,256);//und das zweite bild darunter

          imagesavealpha($gesamt,true);//alpha-kanal soll auch gespeichert werden!
          imagepng($gesamt"gesamt.png",9);//speichern des bildes
          ?>

          Kommentar


          • #6
            Warum verwendest du nicht imagecopymerge??

            The two images will be merged according to pct which can range from 0 to 100. When pct = 0, no action is taken, when 100 this function behaves identically to imagecopy() for pallete images, while it implements alpha transparency for true colour images.
            Tutorials zum Thema Technik:
            https://pilabor.com
            https://www.fynder.de

            Kommentar


            • #7
              Das Handbuch zu lesen hätte es bei dem Thema wirklich auch getan.

              [MOD: Thread verschoben]
              [URL]http://hallophp.de[/URL]

              Kommentar

              Lädt...
              X