index.php:

[code]<?php
$bg = "ffffff";
$descr_file = "images/descr.txt";
$maximg = 8; // images per page

// check if file for image descriptions exists
// create one if not so
if (!file_exists($descr_file)) {
	$fo = @fopen($descr_file, "w");
	$h = opendir("images");
	while ($photo = readdir($h)) {
		if ($photo != "." && $photo != ".." && $photo != "descr.txt") {
			fputs ($fo, $photo.":Voorbeeld tekst\n");
		}
	}
	closedir($h);
	fclose($fo);
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>myPolaroids</title>
<style type="text/css">
body {
	margin: 20px;
	padding: 0;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 0.7em;
	color: #000000;
	background: #ffffff;
}
a:link, a:active {
	color: #000000;
}
a:hover, a:visited {
	color: #666666;
}
</style>
<script language="javascript">

	var imgHtml = new Array();
<?php
// open description file and put images in a array
$fi = @fopen($descr_file, "r");
$i = 0;
while (!feof($fi)) {

	$data = explode(":",fgets($fi, 1024));

	$photo = $data[0];
	$angle = rand(-45, 45);
	
	if ($data[1] == "") {
		$text = $photo;
	} else {
		$text = trim($data[1]);
	} 
	
	if ($data[1] != "") {
		
		$i++;
		
		// get image size for popup
		$img_data = getImageSize("images/".$photo);
		$width = $img_data[0];
		$height = $img_data[1];
		
		// images to display
		echo "    imgHtml[".$i."] = \"<a href=\\\"javascript:;\\\" onclick=\\\"window.open('popup_img.php?name=images/".$photo."','popup','width=".($width+20).",height=".($height+40)."');\\\"><img src=\\\"polaroid.php?bg=".$bg."&photo=images/".$photo."&x=".$x."&y=".$y."&angle=".$angle."&text=".$text."\\\" alt=\\\"".$text."\\\" border=\\\"0\\\"></a>\";\n";
	}
	$totalimg = $i;
}
fclose($fi);
?>	
	// display function
	function displayImages(start, end) {
	
		var dispHtml = "";
		var i;
		var j = 0;
		
		for (i = start; i < start+end; i++) {
			j++;
			dispHtml += imgHtml[i];
			if (j == 4) {
			    dispHtml += "<br>";
				j = 0;
			}
		}
		document.getElementById('polaroids').innerHTML = dispHtml;
	
	}

</script>
</head>
<body>
<h1>myPolaroids</h1>
<p>
	<a href="edit_descr.php">Edit image text here!</a>
</p>
<?php 
	  $pages = round($totalimg / $maximg);
	  echo "Pagina | ";
	  for ($i = 1; $i < $pages; $i++) {
	  	  echo "<a href=\"javascript:displayImages(".(($i*$maximg)-$maximg+1).",".$maximg.");\">".$i."</a> | ";
	  }
?>	  
<div id="polaroids">&nbsp;</div>
<script language="javascript">
    // display first set of images
	displayImages(1,<?php echo $maximg; ?>);
</script>
</body>
</html>[/code]

polaroid.php:

[code]<?php
	$color 	= $_GET["bg"];
	$photo 	= $_GET["photo"];
	$angle	= $_GET["angle"];
	$text 	= $_GET["text"];	

	$r = hexdec(substr($color, 0, 2));
	$g = hexdec(substr($color, 2, 2));
	$b = hexdec(substr($color, 4, 2)); 
	
	$info = getimagesize(stripslashes(str_replace(" ", "%20", $photo)));
	$text = trim(strip_tags(stripslashes(str_replace("_", " ", $text))));
	$polaroid = imagecreatetruecolor(123, 150);
	$bg = imagecolorallocate($polaroid, $r, $g, $b);
	imagefill($polaroid, 0, 0, $bg);
	$scale = ($info[0] > $info[1]) ? (100 / $info[1]) : (100 / $info[0]);

	if ($info[2] == 1) {
		$photo = imagecreatefromgif(stripslashes(str_replace("||", "%20", $photo)));
	} elseif ($info[2] == 2) {
		$photo = imagecreatefromjpeg(stripslashes(str_replace("||", "%20", $photo)));
	} elseif ($info[2] == 3) {
		$photo = imagecreatefrompng(stripslashes(str_replace("||", "%20", $photo)));
	}

	$tmp = imagecreatetruecolor(100, 100);
	imagecopyresampled($tmp, $photo, 0, 0, 0, 0, floor($info[0] * $scale), floor($info[1] * $scale), $info[0], $info[1]);

	imagecopy($polaroid, $tmp, 10, 9, 0, 0, 100, 100);

	$frame = imagecreatefrompng("frame.png");
	imagecopy($polaroid, $frame, 0, 0, 0, 0, 121, 150);

	$text = wordwrap($text, 25, "||", 1);
	$text = explode("||", $text);

	$black = imagecolorallocate($polaroid, 0, 0, 0);

	$text_pos_y = array(123, 125, 132);
	for ($i = 0; $i < 3; $i++)	{
		$width = imagettfbbox(10, 0, "dalek.ttf", $text[$i]);
		$text_pos_x = (110 - $width[2])/2 + 20;
		imagettftext($polaroid, 7, 0, $text_pos_x, $text_pos_y[$i], $black, "dalek.ttf", $text[$i]);
	}

	$polaroid = imagerotate($polaroid, $angle, $bg);

	header("Content-type: image/jpeg");
	imagejpeg($polaroid , "", 100);
	imagedestroy($polaroid);
?>[/code]

popup_img.php:

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>myPolaroids - Popup</title>
</head>
<style type="text/css">
body {
	margin: 10px;
	padding: 0;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 0.7em;
	color: #000000;
	background: #ffffff;
}
a:link, a:active {
	color: #000000;
}
a:hover, a:visited {
	color: #666666;
}
</style>
<body>
<div align="center">
	<?php echo "<img src=\"".$name."\">"; ?><br>
	<a href="javascript:window.close();">close</a>
</div>
</body>
</html>[/code]

edit_descr.php:

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Polaroid-Generator</title>
<style type="text/css">
body {
	margin: 20px;
	padding: 0;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 0.7em;
	color: #000000;
	background: #ffffff;
}
a:link, a:active {
	color: #000000;
}
a:hover, a:visited {
	color: #666666;
}
</style>
</head>
<body>
<h1>myPolaroids - Edit image text</h1>
<p>
	<a href="index.php">back to myPolaroids...</a>
</p>
<?php
	$descr_file = "images/descr.txt";

	if ($_POST["submit"] == "save") {
	
		$postdata = $_POST;
		
		$fo = @fopen($descr_file, "w");
		for ($i = 1; $i < $_POST["count"]+1; $i++) {
		    $file = $postdata["file".$i];
			$data = $postdata["data".$i];
			//echo $file.":".$data."\n";
			fputs($fo, $file.":".$data."\n");
		}
		fclose($fo);
	}

?>
<form action="edit_descr.php" method="post">
<?php

// check if file for image descriptions exists
// create one if not so
if (!file_exists($descr_file)) {
	$fo = @fopen($descr_file, "w");
	$h = opendir("images");
	while ($photo = readdir($h)) {
		if ($photo != "." && $photo != ".." && $photo != "descr.txt") {
			fputs ($fo, $photo.":Voorbeeld tekst\n");
		}
	}
	closedir($h);
	fclose($fo);
}

// open description file and display images
$fi = @fopen($descr_file, "r");
$i = 0;
while (!feof($fi)) {
	
	$data = explode(":",fgets($fi, 1024));
	if ($data[1] != "") {
		$i++;
		echo "<input type=\"hidden\" name=\"file".$i."\" value=\"".$data[0]."\">";
		echo $data[0]." <input type=\"text\" value=\"".$data[1]."\" name=\"data".$i."\"><br>\n"; 	
	}
}
fclose($fi);
echo "<input type=\"hidden\" name=\"count\" value=\"".$i."\">\n";
?>
	<input type="submit" name="submit" value="save">
</form>
</body>
</html>[/code]

