- $imgs_fc = array();
- $imgs_sc = array();
- if (count($img_tags_landscape) == 0 || count($img_tags_portrait) == 0) {
- if (count($img_tags_landscape) == 0) {
- // only portrait
- for ($i = 0; $i < count($img_tags_portrait); $i++) {
- ($i % 2 == 0) ? ($imgs_fc[] = $img_tags_portrait[$i]) : ($imgs_sc[] = $img_tags_portrait[$i]);
- }
- }
- if (count($img_tags_portrait) == 0) {
- // ony landscapes
- for ($i = 0; $i < count($img_tags_landscape); $i++) {
- ($i % 2 == 0) ? ($imgs_fc[] = $img_tags_landscape[$i]) : ($imgs_sc[] = $img_tags_landscape[$i]);
- }
- }
- } else {
- // Mix of landscape and portrait images. Which format is dominating (domformat)?
- $domformat = (count($img_tags_landscape) >= count($img_tags_portrait)) ? 'landscape' : 'portrait';
- if ($domformat == 'landscape') {
- // More or equal landscapes than portraits
- for ($l = 0; $l < count($img_tags_landscape); $l++) {
- // use two landscapes for on portrait
- if ((count($img_tags_landscape) > $l + 1) && (count($img_tags_portrait) > $l)) {
- // we have one more landscape that can be used for the l-th portrait
- $imgs_fc[] = $img_tags_landscape[$l];
- $imgs_fc[] = $img_tags_landscape[$l + 1];
- $imgs_sc[] = $img_tags_portrait[$l];
- $l++;
- } elseif (count($img_tags_portrait) <= $l) {
- // no more portraits available but landscapes
- $imgs_fc[] = $img_tags_landscape[$l];
- }
- }
- }
- if ($domformat == 'portrait') {
- // More portraits than landscapes
- $l = 0;
- for ($p = 0; $p < count($img_tags_portrait); $p++) {
- // use two landscapes for on portrait
- if ((count($img_tags_landscape) > $l + 1)) {
- // we have at least one more landscape that can be used for the p-th portrait
- $imgs_sc[] = $img_tags_landscape[$l];
- $imgs_sc[] = $img_tags_landscape[$l + 1];
- $imgs_fc[] = $img_tags_portrait[$p];
- // used to landscapes:
- $l += 2;
- } else {
- // no more landscapes available
- if ($p % 2 == 0 ) {
- $imgs_fc[] = $img_tags_portrait[$p];
- } else {
- $imgs_sc[] = $img_tags_portrait[$p];
- }
-
- }
- }
- }