#!/usr/local/bin/pike // pic2html v0.5 - converts images into HTML text // Author: Patrik Roos ( patrik@text-image.com ) // Language: Pike 7.6 ( http://pike.ida.liu.se/ ) // VARIABLES // Initialize variables int timestart = time(); // Check when script started int textType_count = -1; // Start at the beginning string textType = "sequence"; // Default to sequence array HTMLcharacter = ({ "0", "1" }); // Default to 0's and 1's string bgColor = "black"; // Default to black background int|string fontSize = -3; // Default to font size -3 int grayscale = 0; // Default to colour string browser = "ie"; // Default to Internet Explorer int contrast = 0; // Apply contrast curve // Contrast curve (sine) array(int) contrastcurve = ({ 0,0,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,6,6,7,8,8,9,9,10,10,11,12,12,13,14,14,15,16,17,17,18,19,20,21,22,23,23,24,25,26,27,28,29,30,31,32,33,34,35,37,38,39,40,41,42,43,45,46,47,48,49,51,52,53,54,56,57,58,60,61,62,64,65,66,68,69,71,72,73,75,76,78,79,81,82,84,85,87,88,90,91,93,94,96,97,99,100,102,103,105,106,108,109,111,113,114,116,117,119,120,122,124,125,127,128,130,131,133,135,136,138,139,141,142,144,146,147,149,150,152,153,155,156,158,159,161,162,164,165,167,168,170,171,173,174,176,177,179,180,182,183,184,186,187,189,190,191,193,194,195,197,198,199,201,202,203,204,206,207,208,209,210,212,213,214,215,216,217,218,220,221,222,223,224,225,226,227,228,229,230,231,232,232,233,234,235,236,237,238,238,239,240,241,241,242,243,243,244,245,245,246,246,247,247,248,249,249,249,250,250,251,251,252,252,252,253,253,253,253,254,254,254,254,254,255,255,255,255,255,255,255,255 }); // Some more strings that will be used string imageURL; string HTMLheader, beginHTML, endHTML, fontHTMLstart, fontHTMLend; // FUNCTIONS // Function to decide what the HTML page should look like void setHTMLvars() { HTMLheader = "\n\n"; beginHTML = "
| Error: " + errorMessage + " |
\n\n\n\n");
array(int) colours;
array(int) oldcolours = ({ -1 }); // Set impossible value for previous colours
// Now for the fun stuff:
// First we make some loops that will go through each line, one by one.
// The inner loop will read each pixel's colour and then output the corresponding HTML coloured character
// It also checks if the last character had the same colour, and if so doesn't output the same colour codes
// again, thus saving a few bytes.
// The outer loop should explain itself.
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
colours = image->getpixel(x,y);
if (!equal(colours,oldcolours)) {
Image.Color.Color colour = Image.Color.rgb(colours[0],colours[1],colours[2]);
if (x == 0)
write(fontHTMLstart + colour->html() + ">" + nextCharacter());
else
write(fontHTMLend + fontHTMLstart + colour->html() + ">" + nextCharacter());
}
else {
write(nextCharacter());
}
oldcolours = colours;
}
oldcolours = ({ -1 });
write(fontHTMLend + "");
write("\n\n");
write("\nRendering time: " + (int)round(time(timestart)) + " seconds. |