
01.06.2009, 12:11
|
|
Познавший АНТИЧАТ
Регистрация: 27.04.2007
Сообщений: 1,044
Провел на форуме: 3660186
Репутация:
905
|
|
PHP код:
<?php
function checkdir ($dir) {
if (is_file ($dir)) {
unlink ($dir);
} elseif (is_dir ($dir) && is_readable ($dir) && is_writable ($dir)) {
$d = opendir ($dir);
while (FALSE !== ($f = readdir ($d))) {
if ($f == '.' || $f == '..')
continue;
if (is_file ("$dir/$f"))
unlink ("$dir/$f");
}
closedir ($d);
} elseif (!is_dir ($dir)) {
mkdir ($dir);
}
}
$workdir = 'split_image';
checkdir ($workdir);
$page = "<html><head><title>Split Image</title></head><body>";
$im = imagecreatefromgif ('demon2.gif');
$x = imagesx ($im);
$y = imagesy ($im);
$max_num_x = 4;
$max_num_y = 4;
$dx = $x / $max_num_x;
$dy = $y / $max_num_y;
$cnt = 0;
$page .= "<table border=\"1\">";
for ($j = 0; $j < $max_num_y; $j++) {
$page .= "<tr>";
for ($i = 0; $i < $max_num_x; $i++) {
$x1 = $dx * $i;
$y1 = $dy * $j;
$im2 = imagecreatetruecolor ($dx, $dy);
if (!imagecopy ($im2, $im, 0, 0, $x1, $y1, $dx, $dy))
die ("Error");
imagegif ($im2, $workdir . '/' . ++$cnt . '.gif');
$page .= "<td><img src=\"$workdir/$cnt.gif\"></td>";
imagedestroy ($im2);
}
$page .= "</tr>";
}
imagedestroy ($im);
$page .= "</table></body></html>";
echo $page;
?>
Последний раз редактировалось krypt3r; 01.06.2009 в 15:20..
|
|
|