Pberndt V4

Direkt zum Inhalt springen


Quellcode Image 2 Ascii.php

Beschreibung

Dieses Script wandelt Bilder in HTML Code (Ascii) um.

Sourcecode

<?php

    /*
        Image 2 Ascii

        Aktion: PHP Scripte für die armen dieser Welt
        Der Erlös geht für mein Pausenbrot drauf

        Copyright (c) 2004 by Phillip 'Firebird' Berndt
    */

   

    if(isset($_FILES['bild']) && $_FILES['bild']['error'] == 0)
    {   
        echo('<body bgcolor="'.$_POST['bgcolor'].'">');
       
        if($_POST['good'])
            echo('<span style="font-family: 04b_25, Arial Unicode MS, Courier New, sans-serif; font-size: 1px; letter-spacing: 0px; line-height: 1px">');
        else
            echo('<span style="font-family: 04b_25, Arial Unicode MS, Courier New, sans-serif; font-size: 10px; letter-spacing: 0px; line-height: 10px;">');
       
        switch($_POST['charset'])
        {
            case 'num':      $charsetFrom = ord('0'); $charsetTo = ord('9'); break;
            case 'at':      $charsetFrom = ord('@'); $charsetTo = ord('@'); break;
            case 'onezero':  $charsetFrom = ord('0'); $charsetTo = ord('1'); break;
        }
       
        move_uploaded_file($_FILES['bild']['tmp_name'], './imgData');
        $mImgSrc = file_get_contents('./imgData');
        unlink('./imgData');
       
        $mImgObj = imagecreatefromstring($mImgSrc);
       
        if(!$mImgObj)
            die('Invalid image');
           
        $imgX = imagesx($mImgObj);
        $imgY = imagesy($mImgObj);
       
        // Größe runterrechnen
        $maxSize = ($_POST['maxsize']);
        if($imgX > $maxSize)
        {
            $imgY = ($maxSize / $imgX * $imgY);
            $imgX = $maxSize;
        }
        if($imgY > $maxSize)
        {
            $imgX = ($maxSize / $imgY * $imgX);
            $imgY = $maxSize;
        }
       
        imagecopyresampled($mImgObj, $mImgObj, 0, 0, 0, 0, $imgX, $imgY, imagesx($mImgObj), imagesy($mImgObj));
       
           
        for($y=0; $y<$imgY; $y++)
        {
            for($x=0; $x<$imgX; $x++)
            {
                $mCol = imagecolorat($mImgObj, $x, $y);
                $rCol = imagecolorsforindex($mImgObj, $mCol);
                imagecolordeallocate($mImgObj, $mCol);
               
                $hCol = sprintf('#%02x%02x%02x', $rCol['red'], $rCol['green'], $rCol['blue']);
               
                if($_POST['good'])
                    echo('<font color="'.$hCol.'">0</font>');
                else
                    echo('<font color="'.$hCol.'">'.chr(rand($charsetFrom, $charsetTo)).'</font>');
            }

            echo('<br />');
            flush();
        }

        echo('</span></body>');
        die();
    }
   
?>
<form enctype="multipart/form-data" method="post" action="<?=$_SERVER['REQUEST_URI']?>">
    <input type="file" name="bild" /><br />
    <input type="text" name="maxsize" value="50" /> Maximale Gr&ouml;&szlig;e des Bildes (Empfohlen: 300 f&uuml;r Gute Qualit&auml;t, sonst 50)<br />
    <select name="bgcolor">
        <option value="white">Wei&szlig;</option>
        <option value="black">Schwarz</option>
    </select> Hintergrundfarbe<br />
    <select name="charset">
        <option value="at">At Zeichen</option>
        <option value="num">Zahlen</option>
        <option value="onezero">Einsen und Nullen</option>
    </select> Zeichensatz<br />
    <input type="checkbox" name="good" value="1" /> Pixelgr&ouml;&szlig;e 1zu1 &uuml;bernehmen<br />
    <input type="submit" />
</form>

Download

Dateiname
Image 2 Ascii.php
Größe
3.33kb