Juste un petit fichier PHP codé en 10 minutes pour générer l’équivalent HTML d’une image. Il nécessite l’extension GD et PHP 4x ou 5x.


$image_precision permet de prendre 1 pixel sur $image_precision pixels.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
 
	$image_path = 'image1.jpg';
	$image_precision = 10;
 
	// Récupération des informations de l'image
	if(file_exists($image_path)) {
		$image = imagecreatefromjpeg($image_path);
		list($image_width, $image_height) = getimagesize($image_path);
 
		echo "<table border=\"0\" style=\"background-color:#000;font-size:8px;border-collapse:collapse;font-family:mono;\">\n";
		for ($i=0 ; $i < $image_height ; $i = $i + $image_precision) {
			echo "\t<tr>";
			for ($j=0 ; $j < $image_width ; $j = $j + $image_precision) {
				$rgb = imagecolorat($image, $j, $i);
				$r = ($rgb >> 16) & 0xFF;
				$g = ($rgb >> 8) & 0xFF;
				$b = $rgb & 0xFF;
				echo "<td style=\"color:rgb($r,$g,$b);height:8px;width:8px;\">&</span></td>";
			}
			echo "</tr>\n";
		}
		echo "</table>\n";
	}
?>

Exemple : Image en Ascii Art
Fichier : Fichier PHP