note 60472 added to function.imagecopyresampled
| From: | com dot hotmail at backglancer | Date: | Sun, 08 Jan 2006 06:32:25 +0000 |
| Subject: | note 60472 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101384@lists.php.net to get a copy of this message | ||
wrote this for a game I was helping develop:
Auto Tile Maker -- takes the image and cuts it in several smaller pieces, deleting the original... i
mean.. this is just for those of you who are lazy, coz the script is simple..
modify at will.
<?
// $newfile is the full address of your newly uploaded file
// $floc = is the location of that file ending with /
// $t is the $_FILES['blah'] of your uploaded file.
// whatever... you guys understand enough to modify this code
$size = getimagesize($newfile);
list($w, $h) = $size;
if ($h > 20 || $w > 20) {
$type = array_pop($size);
switch ($type) {
case 'image/jpeg' : $src_image = imagecreatefromjpeg($newfile); break;
// insert more cases here :) i'm lazy too
default : echo 'not an image!'; return;
}
$i = 0;
for ($y = 0; $y < $h; $y += 20) {
for ($x = 0; $x < $w; $x += 20) {
$i++; // new file names will be like 1monkey.gif 2monkey.gif etc..
$new_image = imagecreatetruecolor(20, 20);
imagecopyresampled ($new_image, $src_image,
0, 0,
$x, $y,
20, 20,
20, 20
);
imagegif($new_image, $floc.$i.$t['name']);
imagedestroy($new_image);
} // x
} // y
unlink($newfile);
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60472
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60472&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60472&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60472&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60472&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60472&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60472&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60472&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60472&report=yes
Search -- http://master.php.net/manage/user-notes.php