1<?php
2/*
3
4 magazinelayout.class.php
5
6 Introduction
7 ============
8 A class for creating magazine-like layouts for images. A Magazine-like layout arranges the images at
9 different sizes so that all images fit within a defined "square box". This can be an attractive way
10 of arranging images when you are dealing with user-uploaded images, or don't have a graphic designer
11 handy to arrange and resize them in photoshop.
12
13 Purpose
14 =======
15 The obvious use for this script is anywhere where more than one user submitted image needs to be presented
16 in a HTML page. I'm thinking product databases, forum image uploads, random image rotations, etc etc.
17 Once you have 10 or so images, you are better off using an AJAX based image gallery, but this script will
18 fill the gap nicely up till that point.
19
20 Layouts
21 =======
22 The layouts that are used depend on the number of landscape and portrait images. For example, if we are
23 given a portrait and 2 landscapes, the layout will appear as follows (different numbers represent different
24 images)...
25
26 11113333
27 11113333
28 22223333
29 22223333
30
31 With 3 landscapes, the layout may appear as such...
32
33 11112222
34 11112222
35 33333333
36 33333333
37
38 With 2 portraits, 1 landscape we use
39
40 11122222222333  or  111222
41 11122222222333      111222
42 11122222222333      333333
43                     333333
44
45 With 3 portraits, we could use either
46
47 111222333  or   11333
48 111222333       11333
49 111222333       22333
50                 22333
51
52 If you have 4 images to display, this class will use any of the following...
53
54 111222   112233   111444
55 111222   112233   222444
56 333444   444444   333444
57 333444   444444
58
59 Logic
60 =====
61 The logic behind these calculations are based on algebra - yes, x + y = z (but a little more complicated).
62 I have attempted to clearly document all calculations, however you will find the tools at http://www.quickmath.com/
63 very useful if you aren't a mathematics expert (I'm certainly not one).
64
65 Requirements
66 ============
67 -A PHP 4.3.x server with GD2.x extension enabled - most PHP shared hosting is suitable
68 -An image resizing script - I have included a very simple one with this bundle
69
70 Usage
71 =====
72
73 //include the class file
74 require_once('magazinelayout.class.php');
75
76 //Define the width for the output area (pixels)
77 $width = 600;
78
79 //Define padding around each image - this *must* be included in your stylesheet (pixels)
80 $padding = 3;
81
82 //Define your template for outputting images
83 $template = "<img src=\"image.php?size=[size]&amp;file=[image]\" alt=\"\" />"; //Don't forget to escape the &
84
85 //create a new instance of the class
86 $mag = new magazinelayout($width,$padding,$template);
87
88 //Add the images in any order
89 $mag->addImage('landscape1.jpg');
90 $mag->addImage('portrait1.jpg');
91 $mag->addImage('landscape2.jpg');
92
93 //display the output
94 echo $mag->getHtml();
95
96 Template
97 ========
98 A different <img> tag will be required for different installations, depending mainly on the image script used.
99 Variables:
100 [size] = The size of the image, either 500, h500 or w500
101 [file] = The filename of the image, eg images/image1.jpg
102
103 The default is...
104 <img src="image.php?size=[size]&file=[image]" alt="" />
105
106 Using Apache's mod_rewrite, a better format might be...
107 <image src="images/[size]/[file]" alt="" />
108 Note your script and server must be configured for this, details of this are out of the scope of this script
109
110 A static looking image URL is better because Google will usually ignore dynamic looking images (they look
111 like PHP scripts, not images)
112
113
114 CSS
115 ===
116 The following CSS is required for padding to work correctly...
117
118 .magazine-image {
119	background: #fff;
120	border: 1px #eee solid;
121 }
122 .magazine-image img {
123	padding: 0px;
124	background: #fff;
125	margin: 2px;
126	border: 1px #eee solid;
127 }
128
129 Padding
130 =======
131 Including padding between images was the most complicated part of this script. On the more complex layouts,
132 the equations double in complexity once padding is added. Padding is implemented as x pixels gap between the
133 images - x is defined when the class is created.
134 The padding you specify *must* be reflected in the stylesheet you use, or the layout will not look right.
135 Because IE deals with padding incorrectly, padding has been implemented as "margin" instead. If a padding of
136 3 is specified in the PHP class, then the CSS class for ".magazine-image img" should reflect a margin of 3px
137 or a margin o 2px + border of 1px. Do not specify padding on the image unless you are prepared to hack the PHP
138 code.
139
140 Rounding
141 ========
142 Almost all of the calculations are done using floating point numbers. Because HTML required whole numbers, the
143 numbers need to be rounded (down) before outputting. On some examples, this makes no difference. On others, the
144 1 or 2 pixels worth of rounding is noticeable. Would welcome any suggestions on this issue for those who want
145 pixel perfect layouts.
146
147 Restrictions
148 ============
149 -There is a current limit of 8 images. This can easily be extended.
150 -Images must be a reasonable quality. Images that are too small are stretched which doesn't look good.
151 -The included image resizing script is very basic. I recommend using a script which caches output. The
152  image resizing script that is right for you will depend on your server configuration and is out of
153  the scope of this class.
154
155 To Do
156 =====
157 There are several obvious improvements that can be made to this script. These include...
158 -Adding code for more than 8 images
159 -Configuring so that low-res images are always shown in the small spots
160 -Allow positioning of images (though this does defeat the purpose)
161 -Include an all-purpose image resizing script with static looking URLs and Image caching
162 -Full testing for version 1 release
163 -Rounding issue explained above
164
165 Copyright
166 =========
167 This file may be used and distributed subject to the LGPL available from http://www.fsf.org/copyleft/lgpl.html
168 If you find this script useful, I would appreciate a link back to http://www.ragepank.com or simply an email
169 to let me know you like it :)
170 You are free (and encouraged) to modify or enhance this class - if you do so, I would appreciate a copy
171 of the changes if it's not too much trouble. Please keep this copyright statement intact, and give fair
172 credit on any derivative work.
173
174 About the Author
175 ================
176 Harvey Kane is a PHP Web developer living and working in Auckland New Zealand. He is interested in developing
177 "best practice" websites, and especially interested in using PHP to automate this process as much as
178 possible. Harvey works as a freelance developer doing CMS websites and SEO under the umbrella of www.harveykane.com,
179 and publishes SEO Articles and tools at www.ragepank.com
180
181 Ragepank.com
182 ============
183 www.ragepank.com is a source of original SEO Articles and tools - PHP based techniques for improving
184 search engine positions, and good practice for web development.
185
186 Support
187 =======
188 I am happy to help with support and installation, so long as all documentation and forum threads are read
189 first. You can contact me at info@ragepank.com
190
191 Thanks
192 ======
193 Thanks to Alexander Burkhardt (www.alex3d.de) for the use of the demo images. The images were taken on
194 the lovely Hokianga Harbour in Northland New Zealand.
195
196 @version 0.9
197 @copyright 2006 Harvey Kane
198 @author Harvey Kane info@ragepank.com
199
200 */
201
202
203class magazinelayout
204{
205	var $images = array();
206	var $_numimages = 0;
207	var $_fullwidth;
208	var $_imagetemplate = "<img src=\"/lib/plugins/gallery/inc/image.php?size=[size]&amp;file=[image]\" alt=\"\" />";
209	var $_padding = 3;
210	var $Img = true;
211
212	function magazinelayout($maxwidth=600,$padding=3,$imagetemplate='')
213	{
214		$this->_fullwidth = $maxwidth;
215		$this->_padding = $padding;
216		if ($imagetemplate != '') $this->_imagetemplate = $imagetemplate;
217	}
218
219
220
221	/* Gets the file extension for a given filename */
222	function _getFileExt($file)
223	{
224		$ext = explode(".", $file);
225		if (count($ext) == 0) return '';
226		return $ext[count($ext)-1];
227	}
228
229
230
231	/* Converts the format of a 2D array from $arr[a][b] to $arr[b][a] - used for sorting the array*/
232	function _transpose($arr)
233	{
234		foreach($arr as $keyx => $valx) {
235			foreach($valx as $keyy => $valy) {
236				$newarr[$keyy][$keyx] = $valy;
237			}
238		}
239		return $newarr;
240	}
241
242
243
244	function addImage($img,$url='')
245	{
246		$filename = $img['meta']->_fileName;
247		if ($url == '') $url = $filename;
248		/* Ensure the file is an image */
249		if (
250			(strtolower($this->_getFileExt($filename)) != "jpg") &&
251			(strtolower($this->_getFileExt($filename)) != "jpeg") &&
252			(strtolower($this->_getFileExt($filename)) != "gif") &&
253			(strtolower($this->_getFileExt($filename)) != "png")
254			 ) {
255			return false;
256		}
257
258		/* Read the dimensions of the image */
259		$imagesize = getimagesize($filename);
260		$w = $imagesize[0];
261		$h = $imagesize[1];
262
263		/* don't include zero sized images */
264		if (($h == 0) || ($w == 0)) return false;
265
266		/* Find the ration of width:height */
267		$ratio = $w / $h;
268
269		/* Set format based on the dimensions */
270		$format = ($w > $h) ? 'landscape' : 'portrait';
271
272		/* Keep a count on the total number of images */
273		$this->_numimages++;
274
275
276		/* Save all image details to an array */
277//		$i = $this->_numimages - 1;
278		$opts = array();
279
280		$opts['filename'] = $filename;
281		$opts['url'] = $url;
282		$opts['format'] = $format;
283		$opts['ratio'] = $ratio;
284		$opts['w'] = $w; //Not currently used
285		$opts['h'] = $h; //Not currently used
286		$opts['img'] = $img;
287
288		$this->images[] = $opts;
289		return true;
290	}
291
292
293	/* Replaces variables into the supplied image template */
294	function insertImage($size,$name)
295	{
296		return str_replace('[image]',$name,str_replace('[size]',$size,$this->_imagetemplate));
297	}
298
299
300	/* New Function for Dokuwiki */
301	function insertImg($size,$img)
302	{
303		global $ID;
304
305		$img = $img['img'];
306		list($width, $height) = getimagesize($img['meta']->_fileName);
307		$ratio = $width / $height;
308
309		/* Decide how we should resize image - fixed width or fixed height */
310		if (substr($size, 0, 1) == 'h') {
311			$type = 'fixedheight';
312		} elseif (substr($size, 0, 1) == 'w') {
313			$type = 'fixedwidth';
314		} elseif ($height > $width) {
315			$type = 'fixedheight';
316		} else {
317			$type = 'fixedwidth';
318		}
319
320		/* Calculate new dimensions */
321		if ($type == 'fixedheight') {
322			$new_width = floor(str_replace('h','',$size) * $ratio);
323			$new_height = str_replace('h','',$size);
324		} else {
325			$new_width = str_replace('w','',$size);
326			$new_height = floor(str_replace('w','',$size) / $ratio);
327		}
328
329		$dim = array('w'=>$new_width,'h'=>$new_height);
330
331	        //prepare img attributes
332	        $i           = array();
333	        $i['width']  = $new_width;
334	        $i['height'] = $new_height;
335	        $i['border'] = 0;
336	        $i['class']  = "magazineImage";
337	        $i['alt']    = $img['meta']->getField('Simple.Title');
338	        $i['style']  = "margin: ".$this->_padding."px padding: 0px;";
339	        $iatt = buildAttributes($i);
340	        $src  = ml($img['id'],$dim);
341
342	        // prepare lightbox dimensions
343	        $w_lightbox = $img['meta']->getField('File.Width');
344	        $h_lightbox = $img['meta']->getField('File.Height');
345	        $dim_lightbox = array();
346	        if($w_lightbox > $img['w_lightbox'] || $h_lightbox > $img['h_lightbox']){
347	            $ratio = $img['meta']->getResizeRatio($img['w_lightbox'],$img['h_lightbox']);
348	            $w_lightbox = floor($w_lightbox * $ratio);
349	            $h_lightbox = floor($h_lightbox * $ratio);
350	            $dim_lightbox = array('w'=>$w_lightbox,'h'=>$h_lightbox);
351	        }
352
353	        //prepare link attributes
354	        $a           = array();
355	        $a['title']  = $img['meta']->getField('Simple.Title');
356	        if($img['lightbox']){
357	            $href   = ml($img['id'],$dim_lightbox);
358	            $a['class'] = "lightbox JSnocheck";
359	            $a['rel']   = "lightbox";
360	        }else{
361	            $href   = ml($img['id'],array('id'=>$ID),$img['direct']);
362	        }
363	        $aatt = buildAttributes($a);
364
365	        // prepare output
366	        $ret  = '';
367	        $ret .= '<a href="'.$href.'" '.$aatt.'>';
368	        $ret .= '<img src="'.$src.'" '.$iatt.' />';
369	        $ret .= '</a>';
370	        return $ret;
371	}
372
373
374	/*
375	IMAGE LAYOUTS
376	=============
377	These layouts are coded based on the number of images.
378	Some fairly heavy mathematics is used to calculate the image sizes and the excellent calculators at
379	http://www.quickmath.com/ were very useful.
380	Each of these layouts outputs a small piece of HTML code with the images and a containing div
381	around each.
382	*/
383
384
385	function get1a($i1) {
386		/*
387		111 or 1
388		       1
389		*/
390
391		$s = floor($this->_fullwidth - ($this->_padding * 2));
392		$html = '';
393
394		if ( !$this->Img )
395			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImage(''.$s,$this->images[$i1]['url'])."</div>\n";
396		else
397			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImg(''.$s,$this->images[$i1])."</div>\n";
398
399		return $html;
400	}
401
402	function get2a($i1,$i2) {
403		/*
404		1122
405
406		Equation: t = 4p + ha + hb Variable: h
407
408		*/
409
410		$a = $this->images[$i1]['ratio'];
411		$b = $this->images[$i2]['ratio'];
412		$t = $this->_fullwidth;
413		$p = $this->_padding;
414
415		$h1 = floor( (4*$p - $t) / (-$a - $b) );
416
417		$html = '';
418
419		if ( !$this->Img ) {
420			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImage('h'.$h1,$this->images[$i1]['url'])."</div>\n";
421			$html .= "<div style=\"float: left;\">".$this->insertImage('h'.$h1,$this->images[$i2]['url'])."</div>\n";
422		} else {
423			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImg('h'.$h1,$this->images[$i1])."</div>\n";
424			$html .= "<div style=\"float: left;\">".$this->insertImg('h'.$h1,$this->images[$i2])."</div>\n";
425		}
426		return $html;
427	}
428
429
430
431
432	function get3a($i1,$i2,$i3) {
433		/*
434		1223
435		*/
436
437		/* To save space in the equation */
438		$a = $this->images[$i3]['ratio'];
439		$b = $this->images[$i1]['ratio'];
440		$c = $this->images[$i2]['ratio'];
441		$t = $this->_fullwidth;
442		$p = $this->_padding;
443
444		/*
445		Enter the following data at http://www.hostsrv.com/webmab/app1/MSP/quickmath/02/pageGenerate?site=quickmath&s1=equations&s2=solve&s3=advanced#reply
446		EQUATIONS
447		t = 6p + ah + bh + ch
448		VARIABLES
449		h
450		*/
451
452		$h1 = floor((6 * $p - $t) / (-$a -$b -$c) );
453
454		$html = '';
455		if ( !$this->Img )
456		{
457			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImage('h'.$h1,$this->images[$i1]['url'])."</div>\n";
458			$html .= "<div style=\"float: left;\">".$this->insertImage('h'.$h1,$this->images[$i3]['url'])."</div>\n";
459			$html .= "<div style=\"float: left;\">".$this->insertImage('h'.$h1,$this->images[$i2]['url'])."</div>\n";
460		} else {
461			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImg('h'.$h1,$this->images[$i1])."</div>\n";
462			$html .= "<div style=\"float: left;\">".$this->insertImg('h'.$h1,$this->images[$i3])."</div>\n";
463			$html .= "<div style=\"float: left;\">".$this->insertImg('h'.$h1,$this->images[$i2])."</div>\n";
464		}
465		return $html;
466	}
467
468
469	function get3b($i1,$i2,$i3) {
470		/*
471		1133
472		2233
473		*/
474
475		/* To save space in the equation */
476		$a = $this->images[$i3]['ratio'];
477		$b = $this->images[$i1]['ratio'];
478		$c = $this->images[$i2]['ratio'];
479		$t = $this->_fullwidth;
480		$p = $this->_padding;
481
482		/*
483		Enter the following data at http://www.hostsrv.com/webmab/app1/MSP/quickmath/02/pageGenerate?site=quickmath&s1=equations&s2=solve&s3=advanced#reply
484		EQUATIONS
485		x/a = w/b + w/c + 2p
486		w+x+4p = t
487		VARIABLES
488		w
489		x
490		*/
491
492		/* width of left column with 2 small images */
493		$w1 = floor(
494		-(
495		(2 * $a * $b * $c * $p + 4 * $b * $c * $p - $b * $c * $t)
496		/
497		($a * $b + $c * $b + $a * $c)
498		)
499		);
500
501		/* width of right column with 1 large image */
502		$w2 = floor(
503		($a * (-4 * $b * $p + 2 * $b * $c * $p - 4 * $c * $p + $b * $t + $c * $t))
504		/
505		($a * $b + $c * $b + $a * $c)
506		);
507
508		$html = '';
509		if ( !$this->Img )
510		{
511			$html .= "<div style=\"float: right; clear: both;\">".$this->insertImage('w'.$w2,$this->images[$i3]['url'])."</div>\n";
512			$html .= "<div style=\"float: left;\">".$this->insertImage('w'.$w1,$this->images[$i1]['url'])."</div>\n";
513			$html .= "<div style=\"float: left;\">".$this->insertImage('w'.$w1,$this->images[$i2]['url'])."</div>\n";
514		} else {
515			$html .= "<div style=\"float: right; clear: both;\">".$this->insertImg('w'.$w2,$this->images[$i3])."</div>\n";
516			$html .= "<div style=\"float: left;\">".$this->insertImg('w'.$w1,$this->images[$i1])."</div>\n";
517			$html .= "<div style=\"float: left;\">".$this->insertImg('w'.$w1,$this->images[$i2])."</div>\n";
518		}
519		return $html;
520	}
521
522
523
524	function get4a($i1,$i2,$i3,$i4) {
525		/*
526		1234
527		*/
528
529		/* To save space in the equation */
530		$a = $this->images[$i1]['ratio'];
531		$b = $this->images[$i2]['ratio'];
532		$c = $this->images[$i3]['ratio'];
533		$d = $this->images[$i4]['ratio'];
534		$t = $this->_fullwidth;
535		$p = $this->_padding;
536
537		/*
538		Enter the following data at http://www.hostsrv.com/webmab/app1/MSP/quickmath/02/pageGenerate?site=quickmath&s1=equations&s2=solve&s3=advanced#reply
539		EQUATIONS
540		t = 6p + ah + bh + ch + dh
541		VARIABLES
542		h
543		*/
544
545		$h1 = floor(
546		(8 * $p - $t)
547		/
548		(-$a -$b -$c -$d)
549		);
550
551		//$h1 = floor($this->_fullwidth / ($this->images[$p1]['ratio'] + $this->images[$p2]['ratio'] + $this->images[$p3]['ratio'] + $this->images[$p4]['ratio']));
552		$html = '';
553
554		if ( !$this->Img )
555		{
556			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImage('h'.$h1,$this->images[$i1]['url'])."</div>\n";
557			$html .= "<div style=\"float: left;\">".$this->insertImage('h'.$h1,$this->images[$i2]['url'])."</div>\n";
558			$html .= "<div style=\"float: left;\">".$this->insertImage('h'.$h1,$this->images[$i3]['url'])."</div>\n";
559			$html .= "<div style=\"float: left;\">".$this->insertImage('h'.$h1,$this->images[$i4]['url'])."</div>\n";
560		} else {
561			$html .= "<div style=\"float: left; clear: both;\">".$this->insertImg('h'.$h1,$this->images[$i1]['url'])."</div>\n";
562			$html .= "<div style=\"float: left;\">".$this->insertImg('h'.$h1,$this->images[$i2])."</div>\n";
563			$html .= "<div style=\"float: left;\">".$this->insertImg('h'.$h1,$this->images[$i3])."</div>\n";
564			$html .= "<div style=\"float: left;\">".$this->insertImg('h'.$h1,$this->images[$i4])."</div>\n";
565		}
566		return $html;
567	}
568
569
570
571	function get4b($i1,$i2,$i3,$i4) {
572		/*
573		11444
574		22444
575		33444
576		*/
577
578		/* To save space in the equation */
579		$a = $this->images[$i4]['ratio'];
580		$b = $this->images[$i1]['ratio'];
581		$c = $this->images[$i2]['ratio'];
582		$d = $this->images[$i3]['ratio'];
583		$t = $this->_fullwidth;
584		$p = $this->_padding;
585
586		/*
587		Enter the following data at http://www.hostsrv.com/webmab/app1/MSP/quickmath/02/pageGenerate?site=quickmath&s1=equations&s2=solve&s3=advanced#reply
588		EQUATIONS
589		x/a = w/b + w/c + 2p
590		w+x+4p = t
591		VARIABLES
592		w
593		x
594		*/
595
596		/* width of left column with 2 small images */
597		$w1 = floor(
598		-(
599		(4 * $a * $b * $c * $d * $p + 4 * $b * $c * $d * $p - $b * $c * $d * $t)
600		/
601		($a * $b * $c + $a * $d * $c + $b * $d * $c + $a * $b * $d)
602		)
603		);
604
605		/* width of right column with 1 large image */
606		$w2 = floor(
607		-(
608		(-4 * $p - (-(1/$c) -(1/$d) -(1/$b)) * (4 * $p - $t) )
609		/
610		( (1/$b) + (1/$c) + (1/$d) + (1/$a) )
611		)
612		);
613
614		$html = '';
615		if ( !$this->Img )
616		{
617			$html .= "<div style=\"float: right; clear: both;\">".$this->insertImage('w'.$w2,$this->images[$i4]['url'])."</div>\n";
618			$html .= "<div style=\"float: left;\">".$this->insertImage('w'.$w1,$this->images[$i1]['url'])."</div>\n";
619			$html .= "<div style=\"float: left;\">".$this->insertImage('w'.$w1,$this->images[$i2]['url'])."</div>\n";
620			$html .= "<div style=\"float: left;\">".$this->insertImage('w'.$w1,$this->images[$i3]['url'])."</div>\n";
621		} else {
622			$html .= "<div style=\"float: right; clear: both;\">".$this->insertImg('w'.$w2,$this->images[$i4])."</div>\n";
623			$html .= "<div style=\"float: left;\">".$this->insertImg('w'.$w1,$this->images[$i1])."</div>\n";
624			$html .= "<div style=\"float: left;\">".$this->insertImg('w'.$w1,$this->images[$i2])."</div>\n";
625			$html .= "<div style=\"float: left;\">".$this->insertImg('w'.$w1,$this->images[$i3])."</div>\n";
626		}
627		return $html;
628	}
629
630
631	function getHtml() {
632
633		/* Sort the images array landscape first, then portrait */
634		$this->images = $this->_transpose($this->images);
635		array_multisort($this->images['format'], SORT_STRING, SORT_ASC, $this->images['img'], $this->images['filename'], $this->images['url'], $this->images['ratio']);
636		$this->images = $this->_transpose($this->images);
637
638		/* Profile explains the makeup of the images (landscape vs portrait) so we can use the best layout eg. LPPP or LLLP */
639		$profile = '';
640		foreach ($this->images as $i) {
641			$profile .= $i['format'] == 'landscape' ? 'L' : 'P';
642		}
643
644		/* Open the containing DIV */
645		$html = '';
646		$html .= "<div class=\"magazine-image\" style=\"width: ".$this->_fullwidth."px;" . (!empty($this->images[$this->_numimages-1]['img']['float']) ? ' float:'.$this->images[$this->_numimages-1]['img']['float'].'; margin: 10px;' : '') . "\">\n";
647
648		//print_r($this->images);
649
650		/* 1 Images */
651		if ($this->_numimages == 1) {
652			$html .= $this->get1a(0);
653		}
654
655		/* 2 Images */
656		if ($this->_numimages == 2) {
657			$html .= $this->get2a(0,1);
658		}
659
660		/* 3 Images */
661		if ($this->_numimages == 3) {
662			if ($profile == 'LLL') {
663			  $html .= $this->get3b(0,1,2);
664				//$html .= $this->get2a(1,2);
665				//$html .= $this->get1a(0);
666			} else {
667				$html .= $this->get3b(0,1,2);
668			}
669		}
670
671		/* 4 Images */
672		if ($this->_numimages == 4) {
673
674			if ($profile == 'LLLP') {
675				$html .= $this->get4b(0,1,2,3);
676			} elseif ($profile == 'LPPP') {
677				$html .= $this->get3a(1,2,3);
678				$html .= $this->get1a(0);
679			} else { // LLLL LLPP PPPP
680				$html .= $this->get2a(2,0);
681				$html .= $this->get2a(1,3);
682			}
683		}
684
685		/* 5 Images */
686		if ($this->_numimages == 5) {
687			if ($profile == 'LLLLL') {
688				$html .= $this->get3a(0,1,2);
689				$html .= $this->get2a(3,4);
690			} elseif ($profile == 'LLLLP') {
691				$html .= $this->get3b(0,1,4);
692				$html .= $this->get2a(2,3);
693			} elseif ($profile == 'LLLPP') {
694				$html .= $this->get3b(0,1,4);
695				$html .= $this->get2a(2,3);
696			} elseif ($profile == 'LLPPP') {
697				$html .= $this->get3b(2,3,4);
698				$html .= $this->get2a(0,1);
699			} elseif ($profile == 'LPPPP') {
700				$html .= $this->get3b(2,3,4);
701				$html .= $this->get2a(0,1);
702			} elseif ($profile == 'PPPPP') {
703				$html .= $this->get2a(4,0);
704				$html .= $this->get3a(1,2,3);
705			}
706		}
707
708		/* 6 Images */
709		if ($this->_numimages == 6) {
710			if ($profile == 'LLLLLL') {
711				$html .= $this->get2a(0,1);
712				$html .= $this->get2a(2,3);
713				$html .= $this->get2a(4,5);
714			} elseif ($profile == 'LLLLLP') {
715				$html .= $this->get4b(0,1,2,5);
716				$html .= $this->get2a(3,4);
717			} elseif ($profile == 'LLLLPP') {
718				$html .= $this->get3b(0,1,4);
719				$html .= $this->get3b(2,3,5);
720			} elseif ($profile == 'LLLPPP') {
721				$html .= $this->get3b(0,1,5);
722				$html .= $this->get3b(2,3,4);
723			} elseif ($profile == 'LLPPPP') {
724				$html .= $this->get3b(0,2,4);
725				$html .= $this->get3b(1,3,5);
726			} elseif ($profile == 'LPPPPP') {
727				$html .= $this->get3b(0,1,5);
728				$html .= $this->get3a(2,3,4);
729			} elseif ($profile == 'PPPPPP') {
730				$html .= $this->get3a(3,4,5);
731				$html .= $this->get3a(0,1,2);
732			}
733		}
734
735		/* 7 Images */
736		if ($this->_numimages == 7) {
737			if ($profile == 'LLLLLLL') {
738				$html .= $this->get3a(0,1,2);
739				$html .= $this->get2a(3,4);
740				$html .= $this->get2a(5,6);
741			} elseif ($profile == 'LLLLLLP') {
742				$html .= $this->get4b(0,1,2,6);
743				$html .= $this->get3a(3,4,5);
744			} elseif ($profile == 'LLLLLPP') {
745				$html .= $this->get4b(0,1,2,5);
746				$html .= $this->get3b(3,4,6);
747			} elseif ($profile == 'LLLLPPP') {
748				$html .= $this->get3b(0,1,5);
749				$html .= $this->get4b(2,3,4,6);
750			} elseif ($profile == 'LLLPPPP') {
751				$html .= $this->get3b(0,1,5);
752				$html .= $this->get4b(2,3,4,6);
753			} elseif ($profile == 'LLPPPPP') {
754				$html .= $this->get3a(4,5,6);
755				$html .= $this->get2a(0,1);
756				$html .= $this->get2a(2,3);
757			} elseif ($profile == 'LPPPPPP') {
758				$html .= $this->get3a(0,1,2);
759				$html .= $this->get4b(3,4,5,6);
760			} elseif ($profile == 'PPPPPPP') {
761				$html .= $this->get4a(0,1,2,3);
762				$html .= $this->get3b(4,5,6);
763			}
764		}
765
766		/* 8 Images */
767		if ($this->_numimages >= 8) {
768			/*
769			Note this code is applied for 8 or more images - any images over 8 are ignored. Adding support
770			for more than 8 images would be easy, but the layouts do start losing their effect as more images
771			are added.
772			*/
773			if ($profile == 'LLLLLLLL') {
774				$html .= $this->get3a(0,1,2);
775				$html .= $this->get2a(3,4);
776				$html .= $this->get3a(5,6,7);
777			} elseif ($profile == 'LLLLLLLP') {
778				$html .= $this->get4b(0,1,2,7);
779				$html .= $this->get2a(3,4);
780				$html .= $this->get2a(5,6);
781			} elseif ($profile == 'LLLLLLPP') {
782				$html .= $this->get4b(0,1,2,6);
783				$html .= $this->get4b(3,4,5,7);
784			} elseif ($profile == 'LLLLLPPP') {
785				$html .= $this->get4b(0,1,2,6);
786				$html .= $this->get4b(3,4,5,7);
787			} elseif ($profile == 'LLLLPPPP') {
788				$html .= $this->get4b(0,1,2,6);
789				$html .= $this->get4b(3,4,5,7);
790			} elseif ($profile == 'LLLPPPPP') {
791				$html .= $this->get3a(4,5,6);
792				$html .= $this->get2a(0,1);
793				$html .= $this->get3a(2,3,7);
794			} elseif ($profile == 'LLPPPPPP') {
795				$html .= $this->get3b(5,6,7);
796				$html .= $this->get2a(0,1);
797				$html .= $this->get3b(2,3,4);
798			} elseif ($profile == 'LPPPPPPP') {
799				$html .= $this->get3b(5,6,7);
800				$html .= $this->get2a(0,1);
801				$html .= $this->get3b(2,3,4);
802			} elseif ($profile == 'PPPPPPP') {
803				$html .= $this->get4a(0,1,2,3);
804				$html .= $this->get4a(4,5,6,7);
805			} else {
806				$html .= $this->get3b(5,4,7);
807				$html .= $this->get2a(1,0);
808				$html .= $this->get3b(2,3,6);
809			}
810		}
811
812		/* Close the containing DIV */
813		$html .= "<div style=\"clear: both;\"></div>\n</div>\n";
814
815		return $html;
816	}
817}
818/* End of Class */
819