예제 #1
0
function courierimage($char, $width = 8, $height = 12, $pdir = 'patterns/')
{
    $im = imagecreate($width, $height);
    $background_color = imagecolorallocate($im, 255, 255, 255);
    $text_color = imagecolorallocate($im, 0, 0, 0);
    imagettftext($im, 10, 0, 0, 10, $text_color, 'cour.ttf', $char);
    $imgarray_0 = img2array($im, $width, $height);
    $imgarray_1 = img_array_split($imgarray_0);
    $imgarray_2 = img_array_split($imgarray_1);
    $ia2name = img_array_name($imgarray_2);
    if (!file_exists($pdir . $ia2name)) {
        mkdir($pdir . $ia2name);
    }
    $ia1name = img_array_name($imgarray_1);
    if (!file_exists($pdir . $ia2name . '/' . $ia1name)) {
        mkdir($pdir . $ia2name . '/' . $ia1name);
    }
    $ia0name = img_array_name($imgarray_0);
    $filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.txt';
    if (!file_exists($filename)) {
        // $handle = fopen($filename,'w');
        writeUTF8File($filename, $char);
    }
    $filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.gif';
    if (!file_exists($filename)) {
        ImageGif($im, $filename);
        chmod($filename, 0777);
    }
    echo '<table><tr><td>' . print_img_array($imgarray_0) . '</td><td>' . print_img_array($imgarray_1) . '</td><td>' . print_img_array($imgarray_2) . "</td><td><img src=\"{$filename}\" /></td></table>";
}
예제 #2
0
function chop_png($path, $pdir = 'patterns/', $chopx = 8, $chopy = 12, $threshold = 0.25)
{
    $tdir = 'temp/';
    $size = getimagesize($path);
    $im = imagecreatefrompng($path);
    $width = $size[0];
    $height = $size[1];
    $output = '';
    for ($y = 0; $y < intval($height / $chopy); $y++) {
        for ($x = 0; $x < intval($width / $chopx); $x++) {
            $dest = imagecreate($chopx, $chopy);
            imagecopy($dest, $im, 0, 0, $x * $chopx, $y * $chopy, $chopx, $chopy);
            $filename = $tdir . $x . '_' . $y . '.gif';
            //gif name
            ImageGif($dest, $filename);
            //write gif
            $da0 = img2array($dest, $chopx, $chopy);
            //1:1
            imagedestroy($dest);
            $da1 = img_array_split($da0, $threshold);
            //1:2
            $da2 = img_array_split($da1, $threshold);
            //1:4
            $da2n = img_array_name($da2);
            //1:4 name
            // $da0n = img_array_name($da0);//1:1 name
            // echo '<img src="'.$filename.'"> -> '.$da0n."\n";
            $dir3 = $pdir;
            if (file_exists($dir3 . $da2n)) {
                // echo $da2n.'<br />';
                $da1n = img_array_name($da1);
                $dir2 = $dir3 . $da2n . '/';
                if (file_exists($dir2 . $da1n)) {
                    $da0n = img_array_name($da0);
                    // echo $da0n.'<br />';
                    $dir1 = $dir2 . $da1n . '/';
                    if (file_exists($dir1 . $da0n . '.txt')) {
                        // echo $da0n.'<br />';
                        $output .= file_get_contents($dir1 . $da0n . '.txt');
                    } else {
                        $scan = scandir($dir1);
                        // echo $scan[3].'<br />';
                        $output .= file_get_contents($dir1 . $scan[3]);
                    }
                } else {
                    $scan = scandir($dir2);
                    array_shift($scan);
                    array_shift($scan);
                    $dirs2vals = array();
                    foreach ($scan as $dname) {
                        $dirs2vals[nameSum($dname)] = $dname;
                    }
                    //print_r($dirs2vals);
                    $weight = nameSum($da1n);
                    if (isset($dirs2vals[$weight])) {
                        $thisdir = $dirs2vals[$weight];
                    } else {
                        $thisdir = array_pop($dirs2vals);
                    }
                    // echo $thisdir.'<br />';
                    $dirs0files = scandir($dir2 . $thisdir);
                    $output .= file_get_contents($dir2 . $thisdir . '/' . $dirs0files[3]);
                }
            } else {
                // echo $da2n.'<br />';
                $scan = scandir($dir3);
                array_shift($scan);
                //get rid of self
                array_shift($scan);
                //get rid of parent
                //store children as weights
                $dirs3vals = array();
                foreach ($scan as $dname) {
                    $dirs3vals[nameSum($dname)] = $dname;
                }
                $weight = nameSum($da2n);
                //get weight of image piece
                asort($dirs3vals);
                if (isset($dirs3vals[$weight])) {
                    $thisdir = $dirs3vals[$weight];
                } else {
                    // echo 'last ';
                    $thisdir = array_pop($dirs3vals);
                    //select the last(darkest)
                }
                // echo $da2n.' -> '.$thisdir.'<br />';
                $tdir2 = $dir3 . $thisdir . '/';
                $subdir = scandir($tdir2);
                array_shift($subdir);
                array_shift($subdir);
                // asort($subdir);
                $subdir = array_pop($subdir) . '/';
                // echo $da2n.' -> '.$subdir.'<br />';
                $subdirFiles = scandir($tdir2 . $subdir);
                $val = file_get_contents($tdir2 . $subdir . $subdirFiles[3]);
                //0 self 1 parent 2 gif 3 txt
                // echo $da2n.' -> '.$val . '<br />';
                $output .= $val;
            }
        }
        //end forx
        $output .= "\n";
    }
    //end fory
    return $output;
}