Zitat von Kery <3! ... richtig Zitat Wie hast du das Stereogramm gemacht, wenn man fragen darf. ... PHP-Code: class StereoImage { // Bild in GD einlesen function getImage($path) { if (ereg(".gif\$", $path)) $image=imageCreateFromGIF($path); else $image=imageCreateFromJPEG($path); return($image); } // Stereogramm aus zwei GD- Bildern erzeugen function createStereo($tileimage, $pictureimage) { // Tile einlesen $tilewidth=imageSX($tileimage); if (!$tilewidth) return(false); $tileheight=imageSY($tileimage); for ($y=0;$y<$tileheight;$y+ + ) for ($x=0;$x<$tilewidth;$x+ + ) { $color=imageColorAt($tileimage, $x, $y); if (!is_array($color)) $color=imageColorsForIndex($tileimage, $color); $color=chr($color[red]).chr($color[green]).chr($color[blue]); $tile[$y][$x]=$color; } // Tiefenbild einlesen $mincolor=256; $picturewidth=imageSX($pictureimage); if (!$picturewidth) return(false); $pictureheight=imageSY($pictureimage); for ($y=0;$y<$pictureheight;$y+ + ) for ($x=0;$x<$picturewidth;$x+ + ) { $color=imageColorAt($pictureimage, $x, $y); if (!is_array($color)) $color=imageColorsForIndex($pictureimage, $color); $color=floor(($color[red]+ $color[green]+ $color[blue])/3); $mincolor=min($mincolor, $color); $maxcolor=max($maxcolor, $color); $picture[$y][$x]=$color; } // Höhenfaktor/- verschiebung berechnen $space=$maxcolor- $mincolor+ 1; $elevation=$mincolor; $factor=$space/($tilewidth*0.1); // Max. 10% Verzerrung // Stereobild erzeugen $picturewidth+ =$tilewidth; $stereoimage=imageCreateTrueColor($picturewidth, $pictureheight); for ($x=0;$x<$picturewidth;$x+ + ) for ($y=0;$y<$pictureheight;$y+ + ) { // Auf Tile mappen $sx=$x % $tilewidth; $sy=$y % $tileheight; // Höhendiff ausrechnen $rx=$x- $tilewidth; $diff=floor(($picture[$y][$rx<0?0:$rx]- $elevation)/$factor)+ $diffs[$y][$rx- $tilewidth]; $diffs[$y][$x- $tilewidth]=$diff; // Höhendiff zum X addieren und clippen $sx+ =$diff; if ($sx>=$tilewidth) $sx- =$tilewidth; else if ($sx<0) $sx+ =$tilewidth; // Pixel kopieren $sourcecolor=$tile[$sy][$sx]; $color=imageColorAllocate($stereoimage, ord($sourcecolor[0]), ord($sourcecolor[1]), ord($sourcecolor[2])); imageSetPixel($stereoimage, $x, $y, $color); } // Sterebild zurückgeben return($stereoimage); } } edit: achja: Mustergrafik Tiefengrafik
class StereoImage { // Bild in GD einlesen function getImage($path) { if (ereg(".gif\$", $path)) $image=imageCreateFromGIF($path); else $image=imageCreateFromJPEG($path); return($image); } // Stereogramm aus zwei GD- Bildern erzeugen function createStereo($tileimage, $pictureimage) { // Tile einlesen $tilewidth=imageSX($tileimage); if (!$tilewidth) return(false); $tileheight=imageSY($tileimage); for ($y=0;$y<$tileheight;$y+ + ) for ($x=0;$x<$tilewidth;$x+ + ) { $color=imageColorAt($tileimage, $x, $y); if (!is_array($color)) $color=imageColorsForIndex($tileimage, $color); $color=chr($color[red]).chr($color[green]).chr($color[blue]); $tile[$y][$x]=$color; } // Tiefenbild einlesen $mincolor=256; $picturewidth=imageSX($pictureimage); if (!$picturewidth) return(false); $pictureheight=imageSY($pictureimage); for ($y=0;$y<$pictureheight;$y+ + ) for ($x=0;$x<$picturewidth;$x+ + ) { $color=imageColorAt($pictureimage, $x, $y); if (!is_array($color)) $color=imageColorsForIndex($pictureimage, $color); $color=floor(($color[red]+ $color[green]+ $color[blue])/3); $mincolor=min($mincolor, $color); $maxcolor=max($maxcolor, $color); $picture[$y][$x]=$color; } // Höhenfaktor/- verschiebung berechnen $space=$maxcolor- $mincolor+ 1; $elevation=$mincolor; $factor=$space/($tilewidth*0.1); // Max. 10% Verzerrung // Stereobild erzeugen $picturewidth+ =$tilewidth; $stereoimage=imageCreateTrueColor($picturewidth, $pictureheight); for ($x=0;$x<$picturewidth;$x+ + ) for ($y=0;$y<$pictureheight;$y+ + ) { // Auf Tile mappen $sx=$x % $tilewidth; $sy=$y % $tileheight; // Höhendiff ausrechnen $rx=$x- $tilewidth; $diff=floor(($picture[$y][$rx<0?0:$rx]- $elevation)/$factor)+ $diffs[$y][$rx- $tilewidth]; $diffs[$y][$x- $tilewidth]=$diff; // Höhendiff zum X addieren und clippen $sx+ =$diff; if ($sx>=$tilewidth) $sx- =$tilewidth; else if ($sx<0) $sx+ =$tilewidth; // Pixel kopieren $sourcecolor=$tile[$sy][$sx]; $color=imageColorAllocate($stereoimage, ord($sourcecolor[0]), ord($sourcecolor[1]), ord($sourcecolor[2])); imageSetPixel($stereoimage, $x, $y, $color); } // Sterebild zurückgeben return($stereoimage); } }
Geändert von Tii-chan (03.04.2008 um 19:02 Uhr) Grund: böser Bilder-Link
Foren-Regeln