Netzwerkstatt.de
  – we screw a bit

 

Welcome

Work shop

JavaScript

$WwJavaScript

CSS

$WwCSS

Bilderrahmen

$WwBilderrahmen

Farbmeister

$WwFarbmeister

Silbentrennung

$WwSilbentrennung

Inhalteverwaltung (CMS)

$WwInhalteverwaltungCMS

GD2

$WwGD2

Fachwörter / Glossar

$WwFachwoerterGlossar

Master

Imprint

GD2

oder – ursprünglich – Gif Draw ist eine Sammlung (Bibliothek) von Verfahren (Funktionen) für die Verarbeitung von Pixelbildern in PHP.
Beschreibung: http://de3.php.net/manual/de/book.image.php
Zwar sind die Funktionen in C geschrieben, aber man kann sie einigermaßen leicht nach PHP übertragen und alsdann ausbessern und ergänzen. Das ist zuweilen nötig, da sie manchmal mit heißer Nadel gestrickt sind.
Beispiel: Das Verfahren imagefilltoborder macht nicht so recht, was ich von ihm erwartete: nämlich was der Farbeimer in Photoshop ist; deshalb habe ich das Verfahren angepaßt und diese Anpassung imagefilllowlands genannt -- hier ist eine Beispielanwendung, die ich für Kistenschieben / Sokoban benötige:

(Kistenbild)


Hier ist der Quellcode des Farbeimer-Verfahrens imageFillLowlands():

function imagefilllowlands ($Bild, $x, $y, $newColor)    {
  global $Wortlautausgabe;
  $findColor = imagecolorat($Bild, $x, $y);
  if ($dii > 10)
    return;
  global $Wortartausgabe;
  if ($findColor < 0)    {    /* Refuse to fill to a non-solid $findColor */
    return;  }
  /* nach links /  left */
  $leftLimit = (-1);
  for ($i=$x; $i>=0; $i--)    {
    if ($Wortlautausgabe) 
      echo \"\n
(2) >>> i: $i; x: $x; y: $y; iii++: \" . $iii++ . \"<<<\"; flush(); $px = imagecolorat($Bild, $i, $y); if (($px != $findColor) && ($px != $newColor) ) { // newColor vermutlich unnötig break; } ImageSetPixel ($Bild, $i, $y, $newColor); // nur hier wird gemalt ... $leftLimit = $i; } /* Seek right */ $rightLimit = $x; $sx = imagesx($Bild); $sy = imagesy($Bild); if ($Wortlautausgabe) {echo \"\n
(3) >>> sx: $sx; sy: $sy\"; flush(); } for ($i=$x+1; $i<$sx; $i++) { if ($Wortlautausgabe) { echo \"\n
(4) >>> i: $i; _ x:i $x; y: $y; _ ..... sx: $sx, sy: $sy ... iii++: \" . $iii++ . \"<<< \"; flush(); } $px = imagecolorat($Bild, $i, $y); if (($px != $findColor) && ($px != $newColor) ) { break; } ImageSetPixel ($Bild, $i, $y, $newColor); // ... und hier. $rightLimit = $i; } /* nach oben / above */ if ($y > 0) { $lastBorder = 1; for ($i=$leftLimit; $i<=$rightLimit; $i++) { $px = imagecolorat($Bild, $i, $y-1); if ($lastBorder) { // if (($px == $findColor) || ($px == $newColor)) { // nicht nötig, das Verfahren kreuzt nicht die eigenen Pfade if (($px == $findColor)) { ImageFillLowlands ($Bild, $i, $y-1, $newColor); $lastBorder = 0; } } else if ( ($px != $findColor) && ($px != $newColor) ) { $lastBorder = 1; } } } /* nach unten / below */ if ($y < ((imagesy($Bild)) - 1)) { $lastBorder = 1; for ($i=$leftLimit; $i<=$rightLimit; $i++) { $px = imagecolorat($Bild, $i, $y+1); if ($lastBorder) { if (($px == $findColor)) { ImageFillLowlands ($Bild, $i, $y+1, $newColor); $lastBorder = 0; } } else if ( ($px != $findColor) && ($px != $newColor) ) { $lastBorder = 1; } } } // return($Bild); } // E N D E des Verfahrens imageFillLowlands()