This example can be used for graphics to xpm to PHP_GTK use, but we first look at this simple code, first understand the principle, said xpm probably few know, had to rewrite into this paradigm. The graphics turn to ASCII.
? # # Convert Map file $Pic = "jerry.jpg" ; # # to convert the string $Ascii = "#" ;
$ImageSize=getimagesize($Pic );
If (is_array($ImageSize )): $Width =$ImageSize[0]; # # Get width $Height =$ImageSize[1]; # # Get length Switch ($ImageSize[2]): # # judgment format, because 4 is SWF, so it's not written out case ' 1 ' : If (imagetypes() & img_gif ): $img=imagecreatefromgif($Pic ); Else: Exit ("system does not support GIF format map" ); EndIf; break; case ' 2 ' : If (imagetypes() & img_jpg ): $img=imagecreatefromjpeg($Pic ); Else: Exit ("system does not support JPG map files" ); EndIf; break; case ' 3 ' : If (imagetypes() & img_png ): $img=imagecreatefrompng($Pic ); Else: Exit (The system does not support PNG format map files) ); EndIf; break; Default: Exit ("System not recognized" ); break; Endswitch; For ($y=1; $y <= $Height ; $y ++): For ($x=1; $x <= $Width ; $x ++): # # Fetch Point Index $index = imagecolorat($img,$x , $y ); # # get RGB color $rgb = imagecolorsforindex($img,$ Index ); # # 255,255,255 (RGB) to FFFFFF (HTML) This format $color = dechex($rgb[Red]). Dechex ($rgb[Green]). Dechex ($rgb[Blue ]); Echo "<font color= $color size=1> $Ascii </font>" ; ENDfor; Echo "<BR>" ; ENDfor; EndIf; ?>
|