pm(30, $imagexL), "imgH"=>pm(100, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][1] = array ( "imgW"=>pm(25, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(30, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][2] = array ( "imgW"=>pm(25, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(55, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][3] = array ( "imgW"=>pm(25, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(80, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][4] = array ( "imgW"=>pm(33, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(30, $imagexL), "imgY"=>pm(20, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][5] = array ( "imgW"=>pm(37, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(63, $imagexL), "imgY"=>pm(20, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][6] = array ( "imgW"=>pm(37, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(30, $imagexL), "imgY"=>pm(60, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][7] = array ( "imgW"=>pm(33, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(67, $imagexL), "imgY"=>pm(60, $imageyL), // coordinates "text" => 1, // show text or not? ); break; case 1: // TEMPLATE TWO // A central image, surrounded by three others with a 100% wide one at its lower half. Three smaller ones line the bottom of the page. $templates["lines"][1] = array ( pm(50, $imagexL), pm(0, $imageyL), // Point 1 (x, y) pm(50, $imagexL), pm(5, $imageyL), // Point 2 (x, y) ); $templates["lines"][2] = array ( pm(0, $imagexL), pm(40, $imageyL), // Point 1 (x, y) pm(25, $imagexL), pm(40, $imageyL), // Point 2 (x, y) ); $templates["lines"][3] = array ( pm(75, $imagexL), pm(40, $imageyL), // Point 1 (x, y) pm(100, $imagexL), pm(40, $imageyL), // Point 2 (x, y) ); $templates["lines"][4] = array ( pm(0, $imagexL), pm(80, $imageyL), // Point 1 (x, y) pm(100, $imagexL), pm(80, $imageyL), // Point 2 (x, y) ); $templates["squares"][1] = array ( pm(25, $imagexL), pm(5, $imageyL), // Point 1 (x, y) pm(75, $imagexL), pm(75, $imageyL), // Point 2 (x, y) ); $templates["squares"][2] = array ( pm(33, $imagexL), pm(80, $imageyL), // Point 1 (x, y) pm(66, $imagexL), pm(110, $imageyL), // Point 2 (x, y) ); $templates["img"][0] = array ( "imgW"=>pm(50, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][1] = array ( "imgW"=>pm(50, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(50, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][2] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(40, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][3] = array ( "imgW"=>pm(50, $imagexL), "imgH"=>pm(70, $imageyL), // width and height of image "imgX"=>pm(25, $imagexL), "imgY"=>pm(5, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][4] = array ( "imgW"=>pm(33, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(80, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][5] = array ( "imgW"=>pm(33, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(33, $imagexL), "imgY"=>pm(80, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][6] = array ( "imgW"=>pm(33, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(66, $imagexL), "imgY"=>pm(80, $imageyL), // coordinates "text" => 0, // show text or not? ); break; case 2: // TEMPLATE THREE // Going for drama and less dialogue! Two thin pics either side, with five short but very wide ones vertically. $templates["squares"][0] = array ( pm(0, $imagexL), pm(5, $imageyL), // Point 1 (x, y) pm(20, $imagexL), pm(85, $imageyL), // Point 2 (x, y) ); $templates["squares"][1] = array ( pm(80, $imagexL), pm(15, $imageyL), // Point 1 (x, y) pm(100, $imagexL), pm(95, $imageyL), // Point 2 (x, y) ); $templates["squares"][2] = array ( pm(20, $imagexL), pm(20, $imageyL), // Point 1 (x, y) pm(80, $imagexL), pm(40, $imageyL), // Point 2 (x, y) ); $templates["squares"][3] = array ( pm(20, $imagexL), pm(60, $imageyL), // Point 1 (x, y) pm(80, $imagexL), pm(80, $imageyL), // Point 2 (x, y) ); $templates["img"][0] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][1] = array ( "imgW"=>pm(80, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(10, $imagexL), "imgY"=>pm(20, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][2] = array ( "imgW"=>pm(80, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(10, $imagexL), "imgY"=>pm(40, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][3] = array ( "imgW"=>pm(80, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(10, $imagexL), "imgY"=>pm(60, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][4] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(20, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(80, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][5] = array ( "imgW"=>pm(20, $imagexL), "imgH"=>pm(80, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(5, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][6] = array ( "imgW"=>pm(20, $imagexL), "imgH"=>pm(80, $imageyL), // width and height of image "imgX"=>pm(80, $imagexL), "imgY"=>pm(15, $imageyL), // coordinates "text" => 0, // show text or not? ); break; case 3: // TEMPLATE FOUR // Another interesting overlaying effect one - three tall panels overlay a dominant single background image. $templates["img"][0] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(100, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][1] = array ( "imgW"=>pm(28, $imagexL), "imgH"=>pm(70, $imageyL), // width and height of image "imgX"=>pm(5, $imagexL), "imgY"=>pm(8, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][2] = array ( "imgW"=>pm(28, $imagexL), "imgH"=>pm(70, $imageyL), // width and height of image "imgX"=>pm(36, $imagexL), "imgY"=>pm(16, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][3] = array ( "imgW"=>pm(28, $imagexL), "imgH"=>pm(70, $imageyL), // width and height of image "imgX"=>pm(67, $imagexL), "imgY"=>pm(24, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["squares"][0] = array ( pm(5, $imagexL), pm(8, $imageyL), // Point 1 (x, y) pm(33, $imagexL), pm(78, $imageyL), // Point 2 (x, y) ); $templates["squares"][1] = array ( pm(36, $imagexL), pm(16, $imageyL), // Point 1 (x, y) pm(64, $imagexL), pm(86, $imageyL), // Point 2 (x, y) ); $templates["squares"][2] = array ( pm(67, $imagexL), pm(24, $imageyL), // Point 1 (x, y) pm(95, $imagexL), pm(94, $imageyL), // Point 2 (x, y) ); break; case 4: // TEMPLATE FIVE - for single images! $templates["img"][0] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(100, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 1, // show text or not? ); break; case -1: // TEMPLATE FIVE - for single images! $templates["img"][0] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(100, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 1, // show text or not? ); break; case 5: // TEMPLATE SIX - Another arrangement of boxes, but some have bigger borders than others // Stolen from http://www.aikidoonline.com/Manga%20comic%20pages/images/images.part2/takemusu02-02v.jpg $templates["img"][0] = array ( "imgW"=>pm(37.3, $imagexL), "imgH"=>pm(21.25, $imageyL), // width and height of image "imgX"=>pm(9, $imagexL), "imgY"=>pm(6.25, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][1] = array ( "imgW"=>pm(47.42, $imagexL), "imgH"=>pm(26.63, $imageyL), // width and height of image "imgX"=>pm(44.5, $imagexL), "imgY"=>pm(0, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][2] = array ( "imgW"=>pm(84.5, $imagexL), "imgH"=>pm(30.42, $imageyL), // width and height of image "imgX"=>pm(9, $imagexL), "imgY"=>pm(28.52, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][3] = array ( "imgW"=>pm(56.49, $imagexL), "imgH"=>pm(39.73, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(60.69, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][4] = array ( "imgW"=>pm(35.67, $imagexL), "imgH"=>pm(39.31, $imageyL), // width and height of image "imgX"=>pm(56.49, $imagexL), "imgY"=>pm(60.69, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["lines"][0] = array ( pm(0, $imagexL), pm(0, $imageyL), // Point 1 (x, y) pm(45, $imagexL), pm(0, $imageyL), // Point 2 (x, y) pm(12.518, $imageyL), // Optional thickness ); $templates["lines"][1] = array ( pm(4.4329, $imagexL), pm(0, $imageyL), // Point 1 (x, y) pm(4.4329, $imagexL), pm(60, $imageyL), // Point 2 (x, y) pm(8.8659, $imagexL), ); $templates["lines"][2] = array ( pm(44.7422, $imagexL), pm(0, $imageyL), // Point 1 (x, y) pm(44.7422, $imagexL), pm(28.8209, $imageyL), // Point 2 (x, y) ); $templates["lines"][3] = array ( pm(0, $imagexL), pm(27.5109, $imageyL), // Point 1 (x, y) pm(100, $imagexL), pm(27.5109, $imageyL), // Point 2 (x, y) pm(3.0567, $imageyL), ); $templates["lines"][4] = array ( pm(0, $imagexL), pm(58.98, $imageyL), // Point 1 (x, y) pm(100, $imagexL), pm(58.98, $imageyL), // Point 2 (x, y) pm(3.0567, $imageyL), ); $templates["lines"][5] = array ( pm(95.876, $imagexL), pm(0, $imageyL), // Point 1 (x, y) pm(95.876, $imagexL), pm(100, $imageyL), // Point 2 (x, y) pm(8.8659, $imagexL), ); $templates["lines"][6] = array ( pm(56.288, $imagexL), pm(60.116, $imageyL), // Point 1 (x, y) pm(56.288, $imagexL), pm(100, $imageyL), // Point 2 (x, y) ); break; case 6: // TEMPLATE SEVEN - Two biggies top and bottom with three smaller ones down the middle. Nice balance. // Stolen from http://tn3-2.deviantart.com/fs11/300W/i/2006/235/1/f/Graphic_novel_03___COLOR_by_JSA.jpg $templates["img"][0] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(40, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(6, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][1] = array ( "imgW"=>pm(100, $imagexL), "imgH"=>pm(37.5, $imageyL), // width and height of image "imgX"=>pm(0, $imagexL), "imgY"=>pm(57, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][2] = array ( "imgW"=>pm(39, $imagexL), "imgH"=>pm(32, $imageyL), // width and height of image "imgX"=>pm(12.5, $imagexL), "imgY"=>pm(10.5, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][3] = array ( "imgW"=>pm(77, $imagexL), "imgH"=>pm(16, $imageyL), // width and height of image "imgX"=>pm(12.6, $imagexL), "imgY"=>pm(43, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][4] = array ( "imgW"=>pm(35, $imagexL), "imgH"=>pm(31.5, $imageyL), // width and height of image "imgX"=>pm(12.5, $imagexL), "imgY"=>pm(60, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["squares"][0] = array ( pm(12.5, $imagexL), pm(10.5, $imageyL), // Point 1 (x, y) pm(51.5, $imagexL), pm(42.3, $imageyL), // Point 2 (x, y) ); $templates["squares"][1] = array ( pm(12.6, $imagexL), pm(43.1, $imageyL), // Point 1 (x, y) pm(90, $imagexL), pm(59.1, $imageyL), // Point 2 (x, y) ); $templates["squares"][2] = array ( pm(12.5, $imagexL), pm(60, $imageyL), // Point 1 (x, y) pm(47.1, $imagexL), pm(91.7, $imageyL), // Point 2 (x, y) ); break; case 7: // TEMPLATE EIGHT - split horizontally in three, the centre panel split in two. An inset at the bottom. // Stolen from http://www.geocities.com/nefarious_guy/042403_blankets184large.jpg $templates["img"][0] = array ( "imgW"=>pm(94, $imagexL), "imgH"=>pm(29.5, $imageyL), // width and height of image "imgX"=>pm(3, $imagexL), "imgY"=>pm(2.5, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][1] = array ( "imgW"=>pm(46, $imagexL), "imgH"=>pm(31, $imageyL), // width and height of image "imgX"=>pm(3, $imagexL), "imgY"=>pm(33.5, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["img"][2] = array ( "imgW"=>pm(45, $imagexL), "imgH"=>pm(31, $imageyL), // width and height of image "imgX"=>pm(51, $imagexL), "imgY"=>pm(33.5, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][3] = array ( "imgW"=>pm(94.5, $imagexL), "imgH"=>pm(30.5, $imageyL), // width and height of image "imgX"=>pm(3, $imagexL), "imgY"=>pm(66, $imageyL), // coordinates "text" => 1, // show text or not? ); $templates["img"][4] = array ( "imgW"=>pm(24.5, $imagexL), "imgH"=>pm(21.5, $imageyL), // width and height of image "imgX"=>pm(70.5, $imagexL), "imgY"=>pm(73.5, $imageyL), // coordinates "text" => 0, // show text or not? ); $templates["squares"][0] = array ( pm(3, $imagexL), pm(2.5, $imageyL), // Point 1 (x, y) pm(97.5, $imagexL), pm(32.5, $imageyL), // Point 2 (x, y) ); $templates["squares"][1] = array ( pm(3, $imagexL), pm(33.5, $imageyL), // Point 1 (x, y) pm(49, $imagexL), pm(64.5, $imageyL), // Point 2 (x, y) ); $templates["squares"][2] = array ( pm(51, $imagexL), pm(33.5, $imageyL), // Point 1 (x, y) pm(97.5, $imagexL), pm(64.5, $imageyL), // Point 2 (x, y) ); $templates["squares"][3] = array ( pm(3, $imagexL), pm(66, $imageyL), // Point 1 (x, y) pm(97.5, $imagexL), pm(97, $imageyL), // Point 2 (x, y) ); $templates["squares"][4] = array ( pm(70.5, $imagexL), pm(73.5, $imageyL), // Point 1 (x, y) pm(95, $imagexL), pm(95, $imageyL), // Point 2 (x, y) ); break; } // IMAGES // Generate a new colour for any colourisings $newColourRGB = array(rand(0,200), rand(0,200), rand(0,200)); $newColour = Image::rgb2hex($newColourRGB); $colourAll = false; //if(rand(0,3)==2) // { // One in three chance of colourising pages $colourAll = true; // } $imgTypes = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG'); // Loop through the template's image settings if(is_array($templates["img"])) { if (count($templates["img"]) < count($PictureData)) { $imgCount = count($PictureData); } else { $imgCount = count($templates["img"]); } for($i=0; $i<$imgCount; $i++) { $imageFullPath = $imgLoc . $PictureData[$i]["O"] . "/"; $imageFullPathFile = $imageFullPath . $PictureData[$i]["P"]; if(!is_file($imageFullPathFile)) { return itDead($imagex, $imagey, "The file\r\n" . $PictureData[$i]["P"] . "\r\nis dead."); } if(!$imLLspecs = @getimagesize($imageFullPathFile)) { return itDead($imagex, $imagey, $PictureData[$i]["P"] . "\r\ndoesn't exist.\r\nThere may not be enough images."); } // To load on images, grab em, draw polys on em, and set the colour of the poly to be transparent. Then merge. Let's try it. $imLLspecs = getimagesize($imageFullPathFile); // Some pics are big and use up a lot of memory to process. If too large, we run out of allocated memory. if($imLLspecs[0] * $imLLspecs[1] > 1440000) { $imLL = imagecreatetruecolor(50, 50); $imLLspecs[0] = 50; $imLLspecs[1] = 50; //continue; } else { // Handle GIFs (1), JPEGs (2) and PNGs(3) switch ($imLLspecs[2]) { case 1: // GIF $imLL = imagecreatefromgif($imageFullPathFile); break; case 2: // JPEG $imLL = imagecreatefromjpeg($imageFullPathFile); break; case 3: // PNG $imLL = imagecreatefrompng($imageFullPathFile); break; default: $imLL = imagecreatetruecolor(50, 50); $imLLspecs[0] = 50; $imLLspecs[1] = 50; break; } } //Take the middle of the image, cropped to the size specified in the template. //Source X = (Image width - Specified width) / 2. //Source Y = (Image height - Specified height) / 2. $TmpIm = $templates["img"][$i]; if($TmpIm["imgW"] <= 0 && $TmpIm["imgH"] <= 0) { continue; } // Hmmm. If the picture is too short, extend it high and make sure its width remains the same ratio. // But if it is too slim, extend its width to fill the wide frame. We must ensure the height is no smaller if it has already been adjusted. // So, adjust height if needed. If new /current width is too slim, make it fatter. In theory, if this is the case after extending its height, // this move will only make it taller. if($imLLspecs[1] < $TmpIm["imgH"]) { $newHeight = $TmpIm["imgH"]; $newWidth = $imLLspecs[0] * ($newHeight / $imLLspecs[1]); } else { $newWidth = $imLLspecs[0]; // This is the case if the picture is bigger than the frame in both directions. $newHeight = $imLLspecs[1]; // But is overwritten if the picture is too slim. Should work. } if($newWidth < $TmpIm["imgW"]) { $newWidth = $TmpIm["imgW"]; $newHeight = $imLLspecs[1] * ($newWidth / $imLLspecs[0]); } // Resize to fill template height/width? $image_r = imagecreatetruecolor($newWidth, $newHeight); imagecopyresized($image_r, $imLL, 0, 0, 0, 0, $newWidth, $newHeight, $imLLspecs[0], $imLLspecs[1]); $cropImY=0; $cropImX=0; if($newWidth > $TmpIm["imgW"]) { // Randomly pick an area along the image's width $cropImX = rand(0,round($newWidth - $TmpIm["imgW"])); } if($newHeight > $TmpIm["imgH"]) { // Bias the cropping towards the top (where faces tend to be) $cropImY = rand(round(($newHeight - $TmpIm["imgH"])/3),round(($newHeight - $TmpIm["imgH"])/5)); } $imCropped = imagecreatetruecolor($TmpIm["imgW"], $TmpIm["imgH"]); imagecopymerge($imCropped, $image_r, 0, 0, $cropImX, $cropImY, $TmpIm["imgW"], $TmpIm["imgH"], 100); $imageEffect = rand(1,3); switch($imageEffect) { //case 2: //$image_r = greyIt($image_r, $newWidth, $newHeight); // Image::greyscale($imCropped); // Image::colourise($imCropped, $newColour); // break; case 3: Image::threshold($imCropped, 120); break; default: if($colourAll) { // Don't colourise if we've applied other effects Image::colourise($imCropped, $newColour); } break; } //imagecopymerge($im, $image_r, $TmpIm["imgX"], $TmpIm["imgY"], $cropImX, $cropImY, $TmpIm["imgW"], $TmpIm["imgH"], 100); imagecopymerge($im, $imCropped, $TmpIm["imgX"], $TmpIm["imgY"], 0, 0, $TmpIm["imgW"], $TmpIm["imgH"], 100); } } $imgFramingOverlay = imagecreatetruecolor($imagex, $imagey); $trans_colour = imagecolorallocatealpha($imgFramingOverlay, 0, 0, 0, 127); imagefill($imgFramingOverlay, 0, 0, $trans_colour); imagecolortransparent($imgFramingOverlay, $trans_colour); $black = imagecolorallocate($imgFramingOverlay, 0, 0, 0); $white = imagecolorallocate($imgFramingOverlay, 255, 255, 255); imagesavealpha( $imgFramingOverlay, true ); // Draw the lines - first the black outlines, then the white insides. Seamless. imagesetthickness($imgFramingOverlay, $frameSpacing + ($penWidth * 2)); imagerectangle($imgFramingOverlay, 0, 0, $imagexL, $imageyL, $black); if(is_array($templates["squares"])) { foreach ($templates["squares"] as $poly) { imagerectangle($imgFramingOverlay, $poly[0], $poly[1], $poly[2], $poly[3], $black); } } if(is_array($templates["lines"])) { foreach ($templates["lines"] as $poly) { if(isset($poly[4])) { // If this line is supposed to be drawn at a thickness other than the default.... imagesetthickness($imgFramingOverlay, $poly[4] + ($penWidth * 2)); imageline($imgFramingOverlay, $poly[0], $poly[1], $poly[2], $poly[3], $black); imagesetthickness($imgFramingOverlay, $frameSpacing + ($penWidth * 2)); // Set it back } imageline($imgFramingOverlay, $poly[0], $poly[1], $poly[2], $poly[3], $black); } } imagesetthickness($imgFramingOverlay, $frameSpacing); imagerectangle($imgFramingOverlay, 0, 0, $imagexL, $imageyL, $white); if(is_array($templates["squares"])) { foreach ($templates["squares"] as $poly) { imagerectangle($imgFramingOverlay, $poly[0], $poly[1], $poly[2], $poly[3], $white); } } if(is_array($templates["lines"])) { foreach ($templates["lines"] as $poly) { if(isset($poly[4])) { // If this line is supposed to be drawn at a thickness other than the default.... imagesetthickness($imgFramingOverlay, $poly[4]); imageline($imgFramingOverlay, $poly[0], $poly[1], $poly[2], $poly[3], $white); imagesetthickness($imgFramingOverlay, $frameSpacing); // Set it back } imageline($imgFramingOverlay, $poly[0], $poly[1], $poly[2], $poly[3], $white); } } // For balloons - pick a shape. Place it along the top or side of each image., and then randomly either display or don't - 1/3 chance if(is_array($templates["img"])) { for($i=0; $i<$imgCount; $i++) { if($templates["img"][$i]["text"] == 1 && rand(1,3)>1) // Check the flag, to see if we want the text or not. and 2/3 chance of showing it { if(rand(1,3)==2) { $textIndex = "T"; } else { $textIndex = "D"; } if(rand(2,2) == 2 && is_array($templates["img"][$i]) && $PictureData[$i][$textIndex] != "") { $imgData = $templates["img"][$i]; imagetxttextfit($imgFramingOverlay, round(8 * $percent), 0, $imgData["imgX"], $imgData["imgY"], $imgData["imgW"], $imgData["imgH"], $black, $PictureData[$i][$textIndex], $penWidth); } } } } // Resize - acheiving anti-alias and smaller images. // $image_p = imagecreatetruecolor($imagex, $imagey); // imagecopyresampled($image_p, $im, 0, 0, 0, 0, $imagex, $imagey, $imagexL, $imageyL); if(is_array($col)) { // $im_colour = imagecreatetruecolor($imagex, $imagey); // $colourise = imagecolorallocate($im_colour, $col["r"], $col["g"], $col["b"]); // imagefill($im_colour, 0, 0, $colourise); // imagecopymerge($image_p, $im_colour, 0, 0, 0, 0, $imagex, $imagey, $colWeight); $userColour = Image::rgb2hex($col); Image::colourise($im, $userColour); } return $imgFramingOverlay; } /* function greyIt($sourceImage, $img_width, $img_height) { // convert to grayscale // note: this will NOT affect your original image, unless // originalFileName and destinationFileName are the same for ($y = 0; $y <$img_height; $y++) { for ($x = 0; $x <$img_width; $x++) { $rgb = imagecolorat($sourceImage, $x, $y); $red = ($rgb >> 16) & 0xFF; $green = ($rgb >> 8) & 0xFF; $blue = $rgb & 0xFF; $gray = round(.299*$red + .587*$green + .114*$blue); // shift gray level to the left $grayR = $gray << 16; // R: red $grayG = $gray << 8; // G: green $grayB = $gray; // B: blue // OR operation to compute gray value $grayColor = $grayR | $grayG | $grayB; // set the pixel color imagesetpixel ($sourceImage, $x, $y, $grayColor); imagecolorallocate ($sourceImage, $gray, $gray, $gray); } } return $sourceImage; }*/ function itDead($x, $y, $z) { $im = imagecreatetruecolor($x, $y); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $black); imagettftext($im, 15, 0, 15, $y/5, $white, "comic", "Fail!!1!1"); imagettftext($im, 7, 0, 15, $y/3, $white, "comic", $z); imagettftext($im, 7, 0, $x/3, $y - $y/6, $white, "comic", "www.llamalan.co.uk"); return $im; } function pm($x, $y) { // The PM function (polygon mark) - parameter one is the percentage wanted of parameter two. $z = $y * ($x / 100); return round($z); } function removeBBCode($x) { // phpbb3's smilies are saved in this format: // ;) // So we want to // a) Drop // c) drop everything from that character onwards // Regular Expression to kill off the HTML tag // We don't want to kill comments yet as that contains the smiley itself, hence the [^!] // the part ".+" matches any string one or more times. // the part "\/>" escapes the forward slash character so we can ask it to go as far as the literal string "/>" // We want to remove the 2nd smiley comment as well $htmlStringSearch = "/<[^!].+?>/"; // Identify smilies. We may be able to do them all in one foul swoop without a fowl loop. // And we can! Woot! If using groups in regular expressions, the matches can be used in replacement strings as $1 (1st group), $2 (2nd group), etc. // The pattern \s* matches 0 or more white space characters $smileySearch = "//"; // So far I've used the question mark after the + (one or more) condition so the matching is not 'greedy'. // Basically, it doesn't keep going even after stumbling over the rest of the pattern //... I think $remainingBBSearch = "/\[.+?\]/"; $arySearches = array($htmlStringSearch, $smileySearch, $remainingBBSearch); $aryReplacements = array("", "$1", ""); return preg_replace($arySearches, $aryReplacements, $x); } function imagetxttextfit($im, $size, $angle, $x, $y, $w, $h, $color, $text, $penWidth) { $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); $text=html_entity_decode($text); // Drop "'s and stuff and use proper chars. Until the web gains sentience, this should not be optional. $text=removeBBCode($text); // Remove any phpbb markup. Particularly troublesome are the smilies. // Start location - Y. Anywhere from top to bottom. // But if a title, it must be top or bottom // If Y <= image height / 3, BoxWidth should be imageWidth/4 and X should be 0+rand(15) or (ImageWidth-(rand(15)-BoxWidth) if(strlen($text) < 25 && rand(1,2)==2) { $size *= 2.5; //$font = "comicbd.ttf"; $font="badabb.ttf"; if (rand(1,2)==2) { $boxY = $y + 10 + rand(0, 30); } else { $boxY = $y + rand($h-250, $h-50); } $boxW = $w * 0.85; $boxX = $x + 10 + rand(0,$w-$boxW+30); } else { //$font = "comic.ttf"; $font="laffayette.ttf"; $boxY = $y + 10 + rand(0, $h); if($boxY-$y <= $h * 0.7) { $boxW = $w*0.25; if (rand(1,2)==2) { $boxX = $x + 10 + rand(0,15); } else { $boxX = ($w+$x) - rand(10,25) - $boxW; } } else { $boxW = $w*0.65; $boxX = $x + 10 + rand(0,$w-$boxW+30); } } $pieces = explode(" ", $text); $count = 0; // $ii = 0; // Loop at least once $size++; // The following loop contains other loops. // The first loop inside the 'do' runs through each word of the text, adding it to the string. // This is done as a loop so that we can work out when to insert a carriage return. // Using the handy imagetftbbox function, we can find out if it is too many pixels wide. // If so, insert a carriage return and continue on the next line. // The containing 'do' loop runs at least once, and repeats the whole process if the box is too high. // If it has to repeat, the font is reduced in size by one, and we try again from scratch. // Eventually, we end up with a nicely filled box that fits inside whatever size of frame is given it. do { // loop. Build newtxt from $pieces until the length of it is greater than linelen. insert \r\n, start again. $i=0; $newText=""; $check = 0; $size--; $count++; while($i < count($pieces) && $check<100) { $check++; $j=""; // Find out the current width of the text $bbox = imagettfbbox ($size, $angle, $font, $j . $pieces[$i]); $textWidth = $bbox[2] - $bbox[0]; // While this width is less than the supplied box width, keep adding them words // If this occurs at least once, check is 0. If it is greater, it means that the next word // cannot fit on one line // Note the calculation $boxW-12 : Later on the text is placed 6px away from left border, so double this to get 6px either side while($textWidth < ($boxW-12) && $i < count($pieces)) { $j .= $pieces[$i]; $i++; $check = 0; if($i < count($pieces)) { $j .= " "; } // Re-evaluate the width of the text $bbox = imagettfbbox ($size, $angle, $font, $j . $pieces[$i]); $textWidth = $bbox[2] - $bbox[0]; } if($check > 0) { // This word can't fit. Reduce font size and try again. $size--; } else { // Cannot squeeze any more words onto this line. Carriage return! $newText .= $j; $newText .= "\r\n"; } } $bbox = imagettfbbox ($size, $angle, $font, $newText); $textWidth = $bbox[2] - $bbox[0]; $textHeight = $bbox[1] - $bbox[7]; $boxH = $textHeight + 10; } while($boxH > $h && $count < 100); $count = 0; // every chance that an image may be too slim with a box too high, which will blatter the server without a safeguard while($boxY + $boxH > ($y + $h - 5) && $count < 100) { $boxY -= 10; $count++; } while($boxX + $boxW > ($x + $w) && $count < 100) { $boxX -= 10; $count++; } while($boxY < 0 && $count < 100) { $boxY += 5; $count++; } // To draw a box/ellipse with the black edge, draw black first offset by penwidth, then draw a size with double the pen width added on... // make sense? Thought not. $penWidth2 = $penWidth*2; // The ellipses only work if the box is not too short. Otherwise, they are way too long. Hence, the check to ensure the box width is nor more than 8 times the height. // Also, only use ellipses if the text takes more than one line. A bit silly otherwise. if(rand(1,2)==2 && $boxW < ($boxH*4) && $boxW < ($x*0.8) && strstr($newText, "\r\n")) { imagefilledellipse ($im, $boxX+round($boxW/2)-5, $boxY+round($boxH/2)-5, ($boxW*1.35)+$penWidth2, ($boxH*1.3)+$penWidth2, $black); imagefilledellipse ($im, $boxX+round($boxW/2)-5, $boxY+round($boxH/2)-5, $boxW*1.35, $boxH*1.3, $white); } else { imagefilledrectangle ($im, $boxX-$penWidth, $boxY-$penWidth, $boxW + $boxX +$penWidth , $boxH + $boxY + $penWidth, $black); imagefilledrectangle ($im, $boxX, $boxY, $boxW +$boxX, $boxH + $boxY, $white); } $boxX += 6; $boxY += 6 + $size; imagettftext($im, $size, $angle, $boxX, $boxY, $color, $font, $newText); } // // class.image.php // version 1.0.0, 2004-08-16 // // Description // // A PHP library of helpful image processing methods. This class does not // need to be instantiated. // // Author // // Andrew Collington, 2004 // php@amnuts.com, http://php.amnuts.com/ // // Feedback // // There is message board at the following address: // // http://php.amnuts.com/forums/index.php // // Please use that to post up any comments, questions, bug reports, etc. You // can also use the board to show off your use of the script. // // License // // This class is available free of charge for personal or non-profit work. If // you are using it in a commercial setting, please contact php@amnuts.com for // payment and licensing terms. // // Support // // If you like this script, or any of my others, then please take a moment // to consider giving a donation. This will encourage me to make updates and // create new scripts which I would make available to you. If you would like // to donate anything, then there is a link from my website to PayPal. // // Examples // // $img = imagecreatefromjpeg('original.jpg'); // Image::colourise($img, '4c63f2'); // imagejpeg($img, 'processed.jpg', 90); // // $img = imagecreatefromjpeg('original.jpg'); // Image::threshold($img, 128); // imagejpeg($img, 'processed.jpg', 90); // // $img = imagecreatefromjpeg('original.jpg'); // Image::greyscale($img); // imagejpeg($img, 'processed.jpg', 90); // // $hex = '#45F2C3'; // $hls = Image::rgb2hls(Image::hex2rgb($hex)); // $hls[0] = 192; // $hls[2] = 0.15; // echo Image::rgb2hex(Image::hls2rgb($hls)); // class Image { /** * Gathers the GD version information * * Sometimes a check for the GD version like this: * * (function_exists('imagecreatetruecolor')) ? 2 : 1; * * can fail. This method retrieves the GD information based on what PHP * reports to be installed. It can return the parsed version as an array, * or just the major version if you want to do a simple check. * * @return int|array * @param bool $justMajor * @access public */ function getGDVersion($justMajor = true) { static $version = array(); if (empty($version)) { ob_start(); phpinfo(); $buffer = ob_get_contents(); ob_end_clean(); if (preg_match('|GD Version([^<]*)|i', $buffer, $matches)) { $version = explode('.', $matches[1]); } else if (preg_match('|GD Version bundled (([^ ]*)|i', $buffer, $matches)) { $version = explode('.', $matches[1]); } else if (preg_match('|GD Version ([^ ]*)|i', $buffer, $matches)) { $version = explode('.', $matches[1]); } } return ($justMajor) ? $version[0] : $version; } /** * Return an RGB colour value array of the pixel at given location. * * The array is returned as: array(0 => r, 1 => g, 2 => b) * * @return array * @param resource &$im a reference to the image * @param int $x coordinate * @param int $y coordinate * @access public */ function getPixelRGB(&$im, $x, $y) { $rgb = imagecolorat($im, $x, $y); return array(($rgb >> 16) & 0xFF, ($rgb >> 8) & 0xFF, $rgb & 0xFF); } /** * A simple metric for colour distance in RGB space * * The arrays are expected to be of the format: * array(0 => r, 1 => g, 2 => b) * * @return float * @param array $rgb1 * @param array $rgb2 * @access public */ function colourDistance($rgb1, $rgb2) { return sqrt(3 * ($rgb2[0] - $rgb1[0]) * ($rgb2[0] - $rgb1[0]) + 4 * ($rgb2[1] - $rgb1[1]) * ($rgb2[1] - $rgb1[1]) + 2 * ($rgb2[2] - $rgb1[2]) * ($rgb2[2] - $rgb1[2])); } /** * Convert a hex colour string into an rgb array. * * Handles colour string in the following formats: * * o #44FF55 * o 4FF55 * o #4F5 * o 4F5 * * @return array * @param string $hex * @access public */ function hex2rgb($hex) { $hex = @preg_replace('/^#/', '', $hex); if (strlen($hex) == 3) { $v = explode(':', chunk_split($hex, 1, ':')); return array(16 * hexdec($v[0]) + hexdec($v[0]), 16 * hexdec($v[1]) + hexdec($v[1]), 16 * hexdec($v[2]) + hexdec($v[2])); } else { $v = explode(':', chunk_split($hex, 2, ':')); return array(hexdec($v[0]), hexdec($v[1]), hexdec($v[2])); } } /** * Convert an rgb array into a hex colour string. * * Handles colour string in the following formats: * * o #44FF55 * o 4FF55 * o #4F5 * o 4F5 * * @return array * @param string $hex * @access public */ function rgb2hex($rgb, $adHash = true) { return sprintf("%s%02X%02X%02X", ($adHash ? '#' : ''), $rgb[0], $rgb[1], $rgb[2]); } /** * Convert an RGB array into HLS colour space. * * Expects array(r, g, b) where r, g, b in [0,255]. The HLS array is * returned as array(h, l, s) where h is in [0,360], l and s in [0,1]. * * Function adapted from 'Computer Graphics: Principles and Practice', * by Foley, van Dam, Feiner and Hughes. Chapter 13; Achromatic and * Colored Light. * * @return array * @param array $rgb * @access public */ function rgb2hls($rgb) { for ($c=0; $c<3; $c++) { $rgb[$c] = $rgb[$c] / 255; } $hls = array(0, 0, 0); $max = max($rgb); $min = min($rgb); $hls[1] = ($max + $min) / 2; if ($max == $min) { $hls[0] = null; $hls[2] = 0; } else { $delta = $max - $min; $hls[2] = ($hls[1] <= 0.5) ? ($delta / ($max + $min)) : ($delta / (2 - $delta)); if ($rgb[0] == $max) { $hls[0] = ($rgb[1] - $rgb[2]) / $delta; } else if ($rgb[1] == $max) { $hls[0] = 2 + ($rgb[2] - $rgb[0]) / $delta; } else { $hls[0] = 4 + ($rgb[0] - $rgb[1]) / $delta; } $hls[0] *= 60; if ($hls[0] < 0) { $hls[0] += 360; } if ($hls[0] > 360) { $hls[0] -= 360; } } ksort($hls); return $hls; } /** * Convert HLS colour space array to RGB colour space. * * Expects HLS array as array(h, l, s) where h in [0,360], l and s each * in [0,1]. Returns array(r, g, b) where r, g, and b each in [0, 255] * * Function adapted from 'Computer Graphics: Principles and Practice', * by Foley, van Dam, Feiner and Hughes. Chapter 13; Achromatic and * Colored Light. * * @return array * @param array $hls * @access public */ function hls2rgb($hls) { $rgb = array(0, 0, 0); $m2 = ($hls[1] <= 0.5) ? ($hls[1] * (1 + $hls[2])) : ($hls[1] + $hls[2] * (1 - $hls[1])); $m1 = 2 * $hls[1] - $m2; if (!$hls[2]) { if ($hls[0] === null) { $rgb[0] = $rgb[1] = $rgb[2] = $hls[1]; } else { return false; } } else { $rgb[0] = Image::_hVal($m1, $m2, $hls[0] + 120); $rgb[1] = Image::_hVal($m1, $m2, $hls[0]); $rgb[2] = Image::_hVal($m1, $m2, $hls[0] - 120); } for ($c=0; $c<3; $c++) { $rgb[$c] = round($rgb[$c] * 255); } return $rgb; } /** * Hue value checker for HSL colour space routine. * * @return float * @param float $n1 * @param float $n2 * @param float $h * @access private * @see Image::hls2rgb() */ function _hVal($n1, $n2, $h) { if ($h > 360) { $h -= 360; } else if ($h < 0) { $h += 360; } if ($h < 60) { return $n1 + ($n2 - $n1) * $h / 60; } else if ($h < 180) { return $n2; } else if ($h < 240) { return $n1 + ($n2 - $n1) * (240 - $h) / 60; } else { return $n1; } } /** * Convert an RGB array into HSV (aka HSB) colour space. * * Expects array(r, g, b) where r, g, b in [0,255]. The HSV array is * returned as array(h, s, v) where h is in [0,360], s and v in [0,1]. * * Function adapted from 'Computer Graphics: Principles and Practice', * by Foley, van Dam, Feiner and Hughes. Chapter 13; Achromatic and * Colored Light. * * @return array * @param array $rgb * @access public */ function rgb2hsv($rgb) { for ($c=0; $c<3; $c++) { $rgb[$c] = $rgb[$c] / 255; } $hsv = array(0, 0, 0); $max = max($rgb); $min = min($rgb); $hsv[2] = $max; $hsv[1] = ($max) ? (($max - $min) / $max) : 0; if (!$hsv[1]) { $hsv[0] = null; } else { $delta = $max - $min; if ($rgb[0] == $max) { $hsv[0] = ($rgb[1] - $rgb[2]) / $delta; } else if ($rgb[1] == $max) { $hsv[0] = 2 + ($rgb[2] - $rgb[0]) / $delta; } else { $hsv[0] = 4 + ($rgb[0] - $rgb[1]) / $delta; } $hsv[0] *= 60; if ($hsv[0] < 0) { $hsv[0] += 360; } } ksort($hsv); return $hsv; } /** * Convert HSV colour space array to RGB colour space. * * Expects HLS array as array(h, s, v) where h in [0,360], s and v each * in [0,1]. Returns array(r, g, b) where r, g, and b each in [0, 255] * * Function adapted from 'Computer Graphics: Principles and Practice', * by Foley, van Dam, Feiner and Hughes. Chapter 13; Achromatic and * Colored Light. * * @return array * @param array $hsv * @access public */ function hsv2rgb($hsv) { if (!$hsv[1]) { if ($hsv[0] === null) { $rgb[0] = $rgb[1] = $rgb[2] = $hsv[2]; } else { return false; } } else { if ($hsv[0] == 360) { $hsv[0] = 0; } $hsv[0] /= 60; $i = floor($hsv[0]); $f = $hsv[0] - $i; $p = $hsv[2] * (1 - $hsv[1]); $q = $hsv[2] * (1 - ($hsv[1] * $f)); $t = $hsv[2] * (1 - ($hsv[1] * (1 - $f))); switch ($i) { case 0: $rgb[0] = $hsv[2]; $rgb[1] = $t; $rgb[2] = $p; break; case 1: $rgb[0] = $q; $rgb[1] = $hsv[2]; $rgb[2] = $p; break; case 2: $rgb[0] = $p; $rgb[1] = $hsv[2]; $rgb[2] = $t; break; case 3: $rgb[0] = $p; $rgb[1] = $q; $rgb[2] = $hsv[2]; break; case 4: $rgb[0] = $t; $rgb[1] = $p; $rgb[2] = $hsv[2]; break; case 5: $rgb[0] = $hsv[2]; $rgb[1] = $p; $rgb[2] = $q; break; } } for ($c=0; $c<3; $c++) { $rgb[$c] = round($rgb[$c] * 255); } return $rgb; } /** * Converts an image resource into a grey-scale version * * @return void * @param resource &$im a reference to the image * @access public */ function greyscale(&$im) { $sx = imagesx($im); $sy = imagesy($im); for ($x = 0; $x < $sx; $x++) { for ($y = 0; $y < $sy; $y++) { $rgb = Image::getPixelRGB($im, $x, $y); $colour = ($rgb[0] + $rgb[1] + $rgb[2]) / 3; imagesetpixel($im, $x, $y, imagecolorallocate($im, $colour, $colour, $colour)); } } } /** * Converts an image resource into a threshold black/white version. * * The threshold level is a value from 0 to 255 (black to white), and any * pixel with a colour below that value will be turned black, and any * pixel above that value will be turned white. * * @return void * @param resource &$im a reference to the image * @param int $level * @access public */ function threshold(&$im, $level = 128) { $sx = imagesx($im); $sy = imagesy($im); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); for ($x = 0; $x < $sx; $x++) { for ($y = 0; $y < $sy; $y++) { $rgb = Image::getPixelRGB($im, $x, $y); $intensity = ($rgb[0] + $rgb[1] + $rgb[2]) / 3; imagesetpixel($im, $x, $y, ($intensity < $level ? $black : $white)); } } } /** * Colourises an image based on given colour. * * @return void * @param resource &$im a reference to the image * @param string|array $setColour * @access public * @see Image::colourise() */ function colorize(&$im, $setColour) { Image::colourise($im, $setColour); } /** * Colourises an image based on given colour. * * The colour to use as the shade/tint can be passed and as hex colour * string or as an RGB array. * * @return void * @param resource &$im a reference to the image * @param string|array $setColour * @access public */ function colourise(&$im, $setColour) { if (is_string($setColour)) { $hls = Image::rgb2hls(Image::hex2rgb($setColour)); } else { $hls = Image::rgb2hls($setColour); } $sx = imagesx($im); $sy = imagesy($im); for ($x = 0; $x < $sx; $x++) { for ($y = 0; $y < $sy; $y++) { $rgb = Image::getPixelRGB($im, $x, $y); $pxhls = Image::rgb2hls($rgb); $pxhls[0] = $hls[0]; $pxhls[2] = $hls[2]; $rgb = Image::hls2rgb($pxhls); imagesetpixel($im, $x, $y, imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2])); } } } } ?>