Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

Announcement

If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2013-10-15 13:11:48

sam
Third Light Staff
Registered: 2013-06-06
Posts: 6

Get Image Previews from a Collection

I recently integrated an IMS into a website. We used the API to load images from a collection in our IMS. Here's how you can do it, too:

First add this PHP code to your website, replacing "put-your-IMS-url-in-here" and "put-your-IMS-API-key-in-here" with your IMS URL and IMS API key:

<?php

	include_once('api_client.php');


	try {
		$myIMSClient = new IMSApiClient(
			"put-your-IMS-url-in-here",
			"put-your-IMS-API-key-in-here"
			);
	} catch (Exception $e) {}


	function getPreviewsFromContainer($containerID,$max = 4) {
		global $myIMSClient;
		$images = array();
		if ($myIMSClient) {
			$options = array(
				"fileLimit" => $max,
				"sortOrder" => "Default",
				"thumbsize" => "480x320"
			);
			$images = $myIMSClient->Files_GetAssetsForParent(
				array(
					"containerId"=>$containerID, 
					"options"=>$options
				)
			);
		}
		return $images;
	}
?>

You can vary your image size by changing the "thumbsize" parameter:

  "thumbsize" => "480x320"

Next create an IMS collection and add some images to it. The API will follow the sort order for set for the collection (in our case we set the sort order to be random). Next, find the collection's containerid this can be seen in the browser's URL bar when on the "viewcontainer.tlx" page.

Insert the images into your page like this (replace $containerID with yours, and $noOfImages with the number you require) :

<?php

	$containerID = "18680087757"; // look in IMS the URL bar for /viewcontainer.tlx?containerid=???
	$noOfImages = 8;
	
	$previews = getPreviewsFromContainer($containerID, $noOfImages);

	foreach ($previews as $image) {
		echo "<img src='" . $image["thumbUrl"] . "' class='home-page-image'>";
	}

?>

Offline

Board footer