24. marts 2003 - 03:01
#28
Nåh.. Men det kan jeg ikke lige få til at virke lige nu. Her er koden. Du kan evt. selv lege lidt med den:
<?php
// Get time
$startTime = time();
// Find out what we've chosen
if (isset($_GET['img'])) {
if (file_exists($_GET['img'] . '.jpg')) {
$fname = $_GET['img'] . '.jpg';
} else {
$fname = 'wolf.jpg';
}
} else {
$fname = 'wolf.jpg';
}
// Load main picture
$imgMain = ImageCreateFromJPEG($fname);
// Generate corners
// Top left
$imgTopLeft = ImageCreate(8, 8);
$colBG = ImageColorAllocate($imgTopLeft, 255, 255, 255);
$colBlack = ImageColorAllocate($imgTopLeft, 0, 0, 0);
ImageFilledArc($imgTopLeft, 8,8, 16,16, 180,270, $colBlack, IMG_ARC_PIE);
ImageColorTransparent($imgTopLeft, $colBlack);
// Top right
$imgTopRight = ImageCreate(8, 8);
$colBG = ImageColorAllocate($imgTopRight, 255, 255, 255);
$colBlack = ImageColorAllocate($imgTopRight, 0, 0, 0);
ImageFilledArc($imgTopRight, 0,8, 16,16, 270,0, $colBlack, IMG_ARC_PIE);
ImageColorTransparent($imgTopRight, $colBlack);
// Bottom left
$imgBottomLeft = ImageCreate(8, 8);
$colBG = ImageColorAllocate($imgBottomLeft, 255, 255, 255);
$colBlack = ImageColorAllocate($imgBottomLeft, 0, 0, 0);
ImageFilledArc($imgBottomLeft, 8,0, 16,16, 90,180, $colBlack, IMG_ARC_PIE);
ImageColorTransparent($imgBottomLeft, $colBlack);
// Bottom right
$imgBottomRight = ImageCreate(8, 8);
$colBG = ImageColorAllocate($imgBottomRight, 255, 255, 255);
$colBlack = ImageColorAllocate($imgBottomRight, 0, 0, 0);
ImageFilledArc($imgBottomRight, 0,0, 16,16, 0,90, $colBlack, IMG_ARC_PIE);
ImageColorTransparent($imgBottomRight, $colBlack);
// Construct final image
$imgSizeX = ImageSX($imgMain);
$imgSizeY = ImageSY($imgMain);
$imgOutput = ImageCreate($imgSizeX, $imgSizeY);
// Allocate colours
$colBG = ImageColorAllocate($imgOutput, 255, 255, 255);
$colBlack = ImageColorAllocate($imgOutput, 0, 0, 0);
$colGreen = ImageColorAllocate($imgOutput, 255, 0, 255);
// Gather the picture
ImageCopy($imgOutput, $imgMain, 0,0, 0,0, $imgSizeX,$imgSizeY);
ImageCopy($imgOutput, $imgTopLeft, 0,0, 0,0, 8,8);
ImageCopy($imgOutput, $imgTopRight, $imgSizeX-8,0, 0,0, 8,8);
ImageCopy($imgOutput, $imgBottomLeft, 0,$imgSizeY-8, 0,0, 8,8);
ImageCopy($imgOutput, $imgBottomRight, $imgSizeX-8,$imgSizeY-8, 0,0, 8,8);
// Draw border
ImageArc($imgOutput, 8,8, 16,16, 180,270, $colGreen);
ImageArc($imgOutput, $imgSizeX-8,8, 16,16, 270,0, $colGreen);
ImageArc($imgOutput, 8,$imgSizeY-8, 16,16, 90,180, $colGreen);
ImageArc($imgOutput, $imgSizeX-8,$imgSizeY-8, 16,16, 0,90, $colGreen);
ImageLine($imgOutput, 0,8, 0,$imgSizeY-8, $colGreen);
ImageLine($imgOutput, 8,0, $imgSizeX-8,0, $colGreen);
ImageLine($imgOutput, 8,$imgSizeY-1, $imgSizeX-8,$imgSizeY-1, $colGreen);
ImageLine($imgOutput, $imgSizeX-1,8, $imgSizeX-1,$imgSizeY-8, $colGreen);
ImageDestroy($imgMain);
ImageDestroy($imgTopLeft);
ImageDestroy($imgTopRight);
ImageDestroy($imgBottomLeft);
ImageDestroy($imgBottomRight);
// Display Creation time
$endTime = time();
$totalTime = $endTime - $startTime;
ImageString($imgOutput, 3, 10,10, "Total time: $totalTime second(s)", $colGreen);
header("Content-type: image/png");
ImagePNG($imgOutput);
ImageDestroy($imgOutput);
?>