<?php
	function artwork ($pic='pic.jpg', $width=300) {
		header("Content-type: image/jpeg");
		$gImg = imagecreatefromjpeg($pic);
		$gTempImg = imagecreatetruecolor(500, 500);
		$gNewImg = imagecreatetruecolor(500, 500);
		$bg = imagecolorallocate($gNewImg, 0, 0, 0);
		
		list($iWidth, $iHeight) = getimagesize($pic);
		
		$iRatio = $width / $iWidth;
		$height = $iHeight * $iRatio;
		
		imagecopyresampled($gTempImg, $gImg, 0, 0, 0, 0, $width, $height, $iWidth, $iHeight);
		
		$iYTotal = 0;
		for ($y = 0; $y <= $height; $y++) {
			$ratio = 0;
			$iYTotal++;
			for ($x = 0; $x <= $width; $x++) {
				$color = imagecolorat($gTempImg, $x, $y);
				$r = ($color >> 16) & 0xFF;
				$g = ($color >> 8) & 0xFF;
				$b = $color & 0xFF;
				$clr = imagecolorallocate($gNewImg, $r, $g, $b);
				imagesetpixel($gNewImg, ($x + 50), ($y + $height - ceil($height - $ratio) + 1), $clr);
				$ratio += 0.05;
			}
		}
		
		$i = 1;
		for ($y = 0; $y <= $height; $y++) {
			if ($y >= ($height / 2) && $y <= ($height - 1)) {
				if ($height > 80) $iAHeight = 80;
				$ratio = 0;
				$alpha = 80 + ($iAHeight / 2) - $i * ($iAHeight / 80) + 20;
				$i++;
				for ($x = 0; $x <= $width; $x++) {
					$color = imagecolorat($gTempImg, $x, $y);
					$r = ($color >> 16) & 0xFF;
					$g = ($color >> 8) & 0xFF;
					$b = $color & 0xFF;
					$clr = imagecolorallocatealpha($gNewImg, $r, $g, $b, $alpha);
					imagesetpixel($gNewImg, (50 + $x), ($height - $y + ceil($height + $ratio) - 3), $clr);
					$ratio += 0.05;
				}
			}
		}
		imagedestroy($gTempImg);
		
		imagejpeg($gNewImg, NULL, 100);
		imagedestroy($gNewImg);
	}
	
	if (isset($_GET['pic']) && !empty($_GET['pic'])) {
		artwork($_GET['pic']);
	} else {
		artwork('pic.jpg', $_GET['w']);
	}
?>