rendered paste body<?phpfunction alpha_blending ($image, $watermark, $image_x, $image_y) { ## lets blend source pixels with source alpha into destination =) for ($y = 0; $y < imagesy($watermark); $y++) { for ($x = 0; $x < imagesx($watermark); $x++) { $argb_s = imagecolorat ($watermark,$x,$y); $argb_d = imagecolorat ($image,$x+$image_x,$y+$image_y); $a_s = ($argb_s >> 24) << 1; $r_s = $argb_s >> 16 & 0xFF; $g_s = $argb_s >> 8 & 0xFF; $b_s = $argb_s & 0xFF; $r_d = $argb_d >> 16 & 0xFF; $g_d = $argb_d >> 8 & 0xFF; $b_d = $argb_d & 0xFF; ## source pixel 100% opaque (alpha == 0) if ($a_s == 0) { $r_d = $r_s; $g_d = $g_s; $b_d = $b_s; } ## source pixel 100% transparent (alpha == 255) else if ($a_s > 253) { ## using source alpha only, we have to mix (100-"some") percent ## of source with "some" percent of destination. } else { $r_d = (($r_s * (0xFF-$a_s)) >> 8) + (($r_d * $a_s) >> 8); $g_d = (($g_s * (0xFF-$a_s)) >> 8) + (($g_d * $a_s) >> 8); $b_d = (($b_s * (0xFF-$a_s)) >> 8) + (($b_d * $a_s) >> 8); } $rgb_d = imagecolorallocatealpha ($image, $r_d, $g_d, $b_d, 0); imagesetpixel ($image, $x+$image_x, $y+$image_y, $rgb_d); } } }$pics = array();global $pics;function makehtml($pics){ print "Creating picIndex.html\n"; foreach( $pics as $fname ) { print "we still know about $fname\n"; }} function makeindex ($dirname){print "inside makeindex\n"; $dir = opendir( $dirname ); while( $fname = readdir( $dir ) ) { if ( preg_match( "//", $fname ) ) {//print $fname; } if ( is_dir ("$dirname/$fname") && $fname != '.' && $fname != "..") { print "$dirname/$fname"; makeindex("$dirname/$fname");//recurse here } if ( preg_match( "/[.]JPG$/", $fname ) ) $pics []= $fname; if ( preg_match( "/[.]jpg$/", $fname ) ) $pics []= $fname; } closedir( $dir ); sort ( $pics ); foreach( $pics as $fname ) { $watermark = imagecreatefrompng( "watermark.png" ); $image = imagecreatefromjpeg( "$dirname/$fname" ); $overlapX =imagesx( $image) - imagesx( $watermark); $overlapY = imagesy( $image) - imagesy( $watermark); alpha_blending($image, $watermark, $overlapX, $overlapY); print "Creating watermark for $fname\n"; imagejpeg( $image, "WaterPics/$fname" ); $im = imagecreatefromjpeg( "$dirname/$fname" ); $ox = imagesx( $im ); $oy = imagesy( $im ); $nx = 150; $ny = floor( $oy * ( $nx / $ox ) ); $ny = 113; $nm = imagecreatetruecolor( $nx, $ny ); $wm = $ox/$nx; $hm = $oy/$ny; $h_height = $ny/2; $w_height = $nx/2; //resize the picture if ( $ox > $oy ) { $adjusted_width = $ox/ $hm; $half_widht = $half_width / 2; $int_width = $half_width - $w_height; imagecopyresampled($nm,$im,-$int_widht,0,0,0,$adjusted_width,$ny,$ox,$oy); } else if ( $ox < $oy ) { $adjusted_height = $oy / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled($nm,$im,0,-$int_height,0,0,$nx,$adjusted_height,$ox,$oy); } else { imagecopyresized( $nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy ); } print "Creating thumb for $fname\n"; //create thumbnail from image imagejpeg( $nm, "ThumbPics/$fname" ); //destroy all image files when finished using them imagedestroy($image); imagedestroy($watermark); imagedestroy($im); imagedestroy($nm); } ob_start(); ?><html><head><title>Thumbnails</title></head><body><table cellspacing="0" cellpadding="2"> <tr> <?php $index = 0; foreach( $pics as $fname ) { ?> <td valign="middle" align="center"> <a href="WaterPics/<?php echo( $fname ); ?>" target="_blank"><img src="ThumbPics/<?php echo( $fname ); ?>" border="0" /></a> </td> <?php $index += 1; if ( $index % 4 == 0 ) { echo( "</tr><tr>" ); } } ?> </tr> </table></body></html><?php $html = ob_get_clean(); $fh = fopen( "picIndex.html", "w" ); fwrite( $fh, $html ); fclose( $fh );?> <?php} $startdirname = "pix";makeindex($startdirname);makehtml($pics);?>