Ankündigung

Einklappen
Keine Ankündigung bisher.

Leidiges Thema Transparenz

Einklappen

Neue Werbung 2019

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

  • Leidiges Thema Transparenz

    Hallo,

    bevor jetzt hier wieder einige Beiträge kommen alla "Suche benutzen" will ich direkt vorwegnehmen das die Beiträge fast alle auf Beispiele verweisen die nicht mehr existieren und ich nicht wirklich weiterkomme.

    Ich hab hier folgenden Ansatz aus einer Methode die das Bild resizen soll... das funktioniert alles wunderbar nur jetzt möchte ich bei Gif's und PNG's die Transparenz behalten

    PHP-Code:
    <?php
    $this
    ->_resized = @imagecreatetruecolor($newWidth$newHeight);        
            
    imagecopyresampled($this->_resized$this->_img0000$newWidth$newHeight$this->_info['width'], $this->_info['height']);
            
            if (
    $this->_info['mime'] == "image/gif" OR $this->_info['mime'] == "image/png")
            {
                
    $trans imagecolortransparent($this->_img);
                
    $alpha_color imagecolorsforindex($this->_img$trans);
                
                
    $AC imagecolorallocatealpha ($this->_resized$alpha_color['red'], $alpha_color['green'], $alpha_color['blue'], $alpha_color['alpha'] );
                
    imagecolortransparent($this->_resized$AC);
            }
    ?>
    Hat vielleicht jemand n Lösungsvorschlag oder ein Link zu einen noch existieren Transparenztutorial?
    Gewisse Dinge behält man besser für sich, z.B. das man gewisse Dinge für sich behält.

  • #2
    Für alle die es interesiert das ist die Lösung...

    PHP-Code:
    <?php
            $this
    ->_resized = @imagecreatetruecolor($newWidth$newHeight);    
            
            
    imageantialias($this->_resizedtrue);
                    
            if (
    $this->_info['mime'] == "image/gif" OR $this->_info['mime'] == "image/png")
            {            
                
    // Transparente Farbe des Quell-Bildes abfragen
                
    $colorTransparent imagecolortransparent($this->_img);

                
    // Parlette kopieren
                
    $this->_imagepalettecopy_exact();

                
    // Zielbild mit transparenter Farbe füllen
                
    imagefill($this->_resized,0,0,$colorTransparent);

                
    // Die Füllfarbe als transparent deklarieren
                
    imagecolortransparent($this->_resized$colorTransparent);
                
                
    imagecopyresized($this->_resized$this->_img0000$newWidth$newHeight$this->_info['width'], $this->_info['height']);
            } 
            else
            {    
                
    imagecopyresampled($this->_resized$this->_img0000$newWidth$newHeight$this->_info['width'], $this->_info['height']);
            }
        }
        
        protected function 
    _imagepalettecopy_exact() {
           for( 
    $c $c imagecolorstotal($this->_img); $c++) {
               
    $col imagecolorsforindex($this->_img$c);  //get color at index 'c' in the color table
               
    imagecolorset($this->_resized$c$col['red'], $col['green'], $col['blue']); //set color at index 'c' to $col in the $dst_image
           
    }
        }
    ?>
    Mir ist dabei aufgefallen das imagecopyresampled bei transparenten Gif's Müll produziert aber imagecopyresized funktioniert problemlos.
    Gewisse Dinge behält man besser für sich, z.B. das man gewisse Dinge für sich behält.

    Kommentar

    Lädt...
    X