note 50308 added to ref.image
| From: | domNOSPAMinic at epicwebservices dot net | Date: | Thu, 24 Feb 2005 12:04:12 +0000 |
| Subject: | note 50308 added to ref.image | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85479@lists.php.net to get a copy of this message | ||
Here's a simple function to deinterlace an entire image or a rectangular area of an image.
- Parameters
$image - the image to operate on
$startodd - set to false to get odd lines, true to get even lines (default: false)
$areax1 - start x value of rectangle (default: 0)
$areay1 - start y value of rectangle (default: 0)
$areax2 - end x value of rectangle (default: width of image)
$areay2 - end y value of rectangle (default: height of image)
<?php
function image_deinterlace(&$image, $startodd, $areax1 = 0, $areay1 = 0, $areax2 = -1, $areay2 =
-1) {
// sanity checking
if (!is_resource($image)) { return $image; }
if ($areax2 == -1) { $areax2 = imagesx($image); }
if ($areay2 == -1) { $areay2 = imagesy($image); }
if ($areax2 <= $areax1) { return $image; }
if ($areay2 - $areay1 < 2) { return $image; }
// if start odd is true, we copy the 2nd line to the 1st
// if start odd is false, we copy the 1st line to the 2nd
if ($startodd) {
for ($y = ($areay1 + 1); $y <= $areay2; $y = $y+2) {
for ($x = $areax1; $x <= $areax2; $x++) {
$curpixel = imagecolorat($image, $x, $y);
imagesetpixel($image, $x, $y - 1, $curpixel);
}
}
} else {
for ($y = $areay1; $y <= $areay2; $y = $y+2) {
for ($x = $areax1; $x <= $areax2; $x++) {
$curpixel = imagecolorat($image, $x, $y);
if ($y + 1 <= $areay2) {
// just in case we're on the boundary
imagesetpixel($image, $x, $y + 1, $curpixel);
}
}
}
}
return $image;
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.image.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50308
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50308&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50308&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50308&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50308&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50308&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50308&report=yes
Search -- http://master.php.net/manage/user-notes.php