img-to-div
Code (php)
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<style type="text/css">div { width: 1px; height: 1px; position: absolute; } </style><?php
function divit ($pic) {
$img = imagecreatefrompng($pic);
$output = '<div style="position: relative;">';
for ($y = 0; $y <= (imagesy($img) - 1); $y++) {
for ($x = 0; $x <= (imagesx($img) - 1); $x++) {
$color = imagecolorat($img, $x, $y);
$color_tran = imagecolorsforindex($img, $color);
$r = ($color >> 16) & 0xFF;
$g = ($color >> 8) & 0xFF;
$b = $color & 0xFF;
if ((1 - $color_tran['alpha'] / 127) != 0) $output .= '<div style="left:' . $x . ';top:' . $y . ';background:rgb(' . $r . ',' . $g . ',' . $b . ');opacity:' . (1 - $color_tran['alpha'] / 127) . ';"><!-- --></div>';
}
}
imagedestroy($img);
$output .= '</div>';
return $output;
}
echo divit($_GET['pic']);
?>
function divit ($pic) {
$img = imagecreatefrompng($pic);
$output = '<div style="position: relative;">';
for ($y = 0; $y <= (imagesy($img) - 1); $y++) {
for ($x = 0; $x <= (imagesx($img) - 1); $x++) {
$color = imagecolorat($img, $x, $y);
$color_tran = imagecolorsforindex($img, $color);
$r = ($color >> 16) & 0xFF;
$g = ($color >> 8) & 0xFF;
$b = $color & 0xFF;
if ((1 - $color_tran['alpha'] / 127) != 0) $output .= '<div style="left:' . $x . ';top:' . $y . ';background:rgb(' . $r . ',' . $g . ',' . $b . ');opacity:' . (1 - $color_tran['alpha'] / 127) . ';"><!-- --></div>';
}
}
imagedestroy($img);
$output .= '</div>';
return $output;
}
echo divit($_GET['pic']);
?>