quantme
quantme

Reputation: 3657

How to order/alternate image array by image width?

Working in an MVC application and getting an image array:

Controller

<?php
// model
$this->load->model('catalog/manufacturer');
// data array
$this->data['manufacturers'] = array();
// database data
$results = $this->model_catalog_manufacturer->getManufacturers();
// populating array
foreach ($results as $result)
  {
  $this->data['manufacturers'][] = array(
    // HTTP_IMAGE is where images are stored
    'thumb' => HTTP_IMAGE . $result['image'],
    'href'  => $this->url->link('product/manufacturer/product', 'manufacturer_id=' . $result['manufacturer_id'])
  );
  }
// view
$this->render();
?>

Images are in different proportional sizes (squared, vertical and horizontal).

How can I order the array (before rendering) alternating one narrow image and one wider? (clients petitions are stranger than imagination).

Upvotes: 0

Views: 162

Answers (1)

Patashu
Patashu

Reputation: 21773

What about doing something like this:

1) Get every image, sort the list by aspect ratio

2) Chop the list into the first half and the second half

3) Alternate using images from the first half and from the second half, according to some algorithm (take from left, take from right or random for each half, so that's 9 possibilities already)

Upvotes: 1

Related Questions