// Functions for extending the GD library.
// Port to PHP by John Jensen July 10 2001 -- original code (in C, for the PHP GD Module) by jernberg@fairytale.se
function ImageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
for ($i = 0; $i < imagecolorstotal($src_img); $i++)
{
// Copy the palette from the source image.
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'], $colors['blue']);
}
// Calculate scaling factors.
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
// Loop for every pixel in the destination image.
for ($j = $src_y; $j < $dst_h; $j++)
{
$sY = $j * $scaleY;
for ($i = $src_x; $i < $dst_w; $i++)
{
$sX = $i * $scaleX;
// Sample four pixels.
$c1 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY));
// Average the red, green and blue values.
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
// Set pixel in dest to nearest available color.
$color = ImageColorClosest ($dst_img, $red, $green, $blue);
ImageSetPixel ($dst_img, $i + $dst_x, $j + $dst_y, $color);
}
}
}
// Adaption of bicubic resample to quadcubic, giving slightly better resamples.
function ImageCopyResampleQuadcubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
for ($i = 0; $i < imagecolorstotal($src_img); $i++)
{
// get pallete. Is this algoritm correct?
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'], $colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX1 = $scaleX / 4.0;
$scaleY1 = $scaleY / 4.0;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
$scaleX3 = $scaleX1 + scaleY2;
$scaleY3 = $scaleY1 + scaleY2;
for ($j = $src_y; $j < $dst_h; $j++)
{
$sY = $j * $scaleY;
for ($i = $src_x; $i < $dst_w; $i++)
{
$sX = $i * $scaleX;
$c11 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX), (int)($sY)));
$c12 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX1), (int)($sY)));
$c13 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX2), (int)($sY)));
$c14 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX3), (int)($sY)));
$c21 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX), (int)($sY+$scaleY1)));
$c22 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX1), (int)($sY+$scaleY1)));
$c23 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX2), (int)($sY+$scaleY1)));
$c24 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX3), (int)($sY+$scaleY1)));
$c31 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX), (int)($sY+$scaleY2)));
$c32 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX1), (int)($sY+$scaleY2)));
$c33 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX2), (int)($sY+$scaleY2)));
$c34 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX3), (int)($sY+$scaleY2)));
$c41 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX), (int)($sY+$scaleY3)));
$c42 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX1), (int)($sY+$scaleY3)));
$c43 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX2), (int)($sY+$scaleY3)));
$c44 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int)($sX+$scaleX3), (int)($sY+$scaleY3)));
$red = (int) (($c11['red'] + $c12['red'] + $c13['red'] + $c14['red']
+ $c21['red'] + $c22['red'] + $c23['red'] + $c24['red']
+ $c31['red'] + $c32['red'] + $c33['red'] + $c34['red']
+ $c41['red'] + $c42['red'] + $c43['red'] + $c44['red']) / 16);
$green = (int) (($c11['green'] + $c12['green'] + $c13['green'] + $c14['green']
+ $c21['green'] + $c22['green'] + $c23['green'] + $c24['green']
+ $c31['green'] + $c32['green'] + $c33['green'] + $c34['green']
+ $c41['green'] + $c42['green'] + $c43['green'] + $c44['green']) / 16);
$blue = (int) (($c11['blue'] + $c12['blue'] + $c13['blue'] + $c14['blue']
+ $c21['blue'] + $c22['blue'] + $c23['blue'] + $c24['blue']
+ $c31['blue'] + $c32['blue'] + $c33['blue'] + $c34['blue']
+ $c41['blue'] + $c42['blue'] + $c43['blue'] + $c44['blue']) / 16);
$color = ImageColorClosest ($dst_img, $red, $green, $blue);
ImageSetPixel ($dst_img, $i + $dst_x, $j + $dst_y, $color);
}
}
}
//
// Function to check if an image file is local, and if it is, to get the image size.
//
function ImageTag($pic, $alt, $align)
{
global $_server;
if ($pic) {
if ($alt)
$showAlt = " alt=\"$alt\"";
if ($align)
$showAlign = " align=\"$align\"";
if (ereg("^http://", $pic)) {
// Image is on a remote server, so don't try to get size:
echo " ";
} else {
// Check whether relative or absolute.
if (ereg("^/", $pic)) {
// Absolute - get root directory.
$path=dirname(realpath($_SERVER["DOCUMENT_ROOT"]));
$filename="$path$pic";
} else {
// Relative - get current directory.
$path=dirname(realpath($_SERVER["PATH_TRANSLATED"]));
$filename="$path/$pic";
}
//echo "$filename ";
// Local file, so get the image size.
if ($size=GetImageSize($filename)) {
echo " ";
}
}
}
}
//
// Function to check if an image file is local, and if it is, to get the image size.
//
function MiniPicTag($pic, $alt, $align)
{
if ($pic) {
if ($alt)
$showAlt = " alt=\"$alt\"";
if ($align)
$showAlign = " align=\"$align\"";
if (ereg("jpg$", $pic)) {
// Minipics only apply to JPEG images at the moment.
echo " ";
}
}
}
?>
Taff DiaryTaff News Index
|
15 Sep 2004
| Home I go Two days in bermuda have breezed by very quickly... Full Story | | |
14 Sep 2004
| Sun and more Yesterday after failing to send email, but recieving a bckload,... Full Story | | |
12 Sep 2004
| Bermuda Bermuda is small but pretty, like a warm dalkey I... Full Story | | |
12 Sep 2004
| Nics Farewell Its 1... Full Story | | |
11 Sep 2004
| Teds to Nics Today is good, I wake up late and its nice,... Full Story | | |
10 Sep 2004
| Strike the plastic So, I get up today ion time, and everything is... Full Story | | |
09 Sep 2004
| Jekyl and Hyde So, when I got to amwerica, my good friend and... Full Story | | |
09 Sep 2004
| Communication concern So I have no internet connection, and no WI-FI so... Full Story | | |
08 Sep 2004
| Great evening After the visit to Tor, I headed off with knowledge... Full Story | | |
08 Sep 2004
| Jesus, what a Day downs then great UPS!! I wake up this morning to find that ist lashing... Full Story | | |
07 Sep 2004
| Its over now baby Woke up this morning at a reasonable time, even though... Full Story | | |
06 Sep 2004
| And now, the time is near..... Last days' at a convention are always hectic... Full Story | | |
06 Sep 2004
| Fund Raising I eventually got to bed at 8am, and was stunned... Full Story | | |
05 Sep 2004
| Parties and Pals Following after the Hugo's there was an Interaction Hugo Loser's... Full Story | | |
05 Sep 2004
| Presenting the Hugo Last night, I prseneted the Hugo award for Best Fanwriter... Full Story | | |
04 Sep 2004
| Celebrations Immediatly after the award ceremony we, Joe, Geri Sullivan, Mark... Full Story | | |
04 Sep 2004
| A Great moment James White won the Retro Hugo for best Fanzine of... Full Story | 
| |
02 Sep 2004
| Longest day Today has been a good day, felt like I would... Full Story | | |
01 Sep 2004
| A good night Its hard to be at two places at once, but... Full Story | | |
01 Sep 2004
| Busy day so Far well I had volunteered yesterday and today I continued... Full Story | | |
01 Sep 2004
| A good evening Am a light weight, went to bed at about half... Full Story | | |
31 Aug 2004
| In Boston Boston is green and pleasant, not too hot, and not... Full Story | | |
31 Aug 2004
| Leaving Dublin Well I am off, all set and ready to go,... Full Story | | |
30 Aug 2004
| Packing and Bedlam The last two days have been manic, packing and preparing... Full Story | | |
29 Aug 2004
| Website Launched With barely hours to go to my departure, the amazing... Full Story | | |
|
|
|