Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- set_time_limit( 3600 );
- $pathtoImage = 'img2.png'; /* Can be ANY PNG image! */
- /* Due to the large output size, only a PART of the image should be converted to HTML code */
- $startWidth = 250;
- $startHeight = 250;
- $width = 101; /* (startWidth + width) < actualimageWidth */
- $height = 101; /* (startHeight + height) < actualimageHeight */
- /* Don't edit below this line */
- $im = @imagecreatefrompng( $pathtoImage );
- unlink( 'image1.html' );
- unlink( 'image2.html' );
- unlink( 'image3.html' );
- $fid1 = fopen( 'image1.html', 'w+');
- $fid2 = fopen( 'image2.html', 'w+');
- $fid3 = fopen( 'image3.html', 'w+');
- fwrite( $fid1, '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body>' );
- fwrite( $fid2, '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body>' );
- fwrite( $fid3, '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body>' );
- $i = 0;
- if( ($startWidth + $width) > imagesx( $im ) ) echo 'Please lower the number for "$startWidth + $width"<br />';
- if( ($startHeight + $height) > imagesx( $im ) ) echo 'Please lower the number for "$startWidth + $width"<br />';
- fwrite( $fid1, '<style type="text/css">.i{width:' . ($width-1) . 'px;height:' . ($height-1) . 'px;}' );
- fwrite( $fid2, '<style type="text/css">.i{width:' . ($width-1) . 'px;height:' . ($height-1) . 'px;}' );
- fwrite( $fid3, '<style type="text/css">.i{width:' . ($width-1) . 'px;height:' . ($height-1) . 'px;}' );
- for( $x = $startWidth; $x < ($startWidth+$width)-1; $x++ ) {
- for( $y = $startHeight; $y < ($startHeight+$height)-1; $y++ ) {
- $p = imagecolorat( $im, $x, $y );
- $a = imagecolorsforindex( $im, $p );
- $a = dechex( $a['red'] ) . dechex( $a['green'] ) . dechex( $a['blue'] );
- fwrite( $fid1, '#a' . $i++ . '{background-color:#' . $a . ';float:left;height:1px;width:1px;}' );
- fwrite( $fid2, '#a' . $i . '{background-color:#' . $a . ';}' );
- if( !isset( $b[$a] ) )
- $b[$a] = 1;
- else
- $b[$a]++;
- } }
- $i = 0;
- foreach( $b AS $colour => $times ) {
- if( $times == 1 ) {
- $b[ $colour ] = 'id="a' . $i . '" class="d"';
- fwrite( $fid3, '#a' . $i++ . '{background-color:#' . $colour . ';}' );
- }else{
- $b[ $colour ] = 'class="a' . $i . ' d"';
- fwrite( $fid3, '.a' . $i++ . '{background-color:#' . $colour . ';}' );
- } }
- $i = 0;
- $html1 = '<div class="i">';
- $html2 = '<div class="i">';
- $html3 = '<div class="i">';
- for( $x = $startWidth; $x < ($startWidth+$width)-1; $x++ ) {
- for( $y = $startHeight; $y < ($startHeight+$height)-1; $y++ ) {
- $p = imagecolorat( $im, $x, $y );
- $a = imagecolorsforindex( $im, $p );
- $a = dechex( $a['red'] ) . dechex( $a['green'] ) . dechex( $a['blue'] );
- $html1 .= '<div id="a' . $i . '" class="d"></div>';
- $html2 .= '<div id="a' . $i++ . '"></div>';
- $html3 .= '<div ' . $b[$a] . '></div>';
- }
- }
- fwrite( $fid2, ".d{float:left;height:1px;width:1px;}");
- fwrite( $fid3, ".d{float:left;height:1px;width:1px;}");
- fwrite( $fid1, '</style>' . $html1 . '</div></body></html>' );
- fwrite( $fid2, '</style>' . $html2 . '</div></body></html>' );
- fwrite( $fid3, '</style>' . $html3 . '</div></body></html>' );
- fclose( $fid1 );
- fclose( $fid2 );
- fclose( $fid3 );
- imagedestroy($im);
- echo '<a href="./image1.html">image1.html</a></br>';
- echo '<a href="./image1.html">image2.html</a></br>';
- echo '<a href="./image1.html">image3.html</a></br>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement