Home Downloads Tera-WURFL Explorer Forums Submit User Agent

Device Image

From Tera-WURFL

Jump to: navigation, search

As of Tera-WURFL 2.1.2, you can detect and display an image of the detected mobile device.

[edit] Getting Started with Device Images

[edit] Downloading the Images

The current collection of device images is available from the WURFL Project. Once the images archive is downloaded, unzip it to a location that is available from the Internet. Normally they are located in a folder called device_pix.

[edit] Detecting the Device Image

The following code demonstrates the usage of the TeraWurflDeviceImage and displaying the image that is detected.

<?php
require_once 'TeraWurfl.php';
require_once 'TeraWurflUtils/TeraWurflDeviceImage.php';
$wurflObj = new TeraWurfl();
$wurflObj->getDeviceCapabilitiesFromAgent();
$image = new TeraWurflDeviceImage($wurflObj);
/**
 * The location of the device images as they are accessed on the Internet
 * (ex. '/device_pix/', 'http://www.mydomain.com/pictures/')
 * The filename of the image will be appended to this base URL
 */
$image->setBaseURL('/device_pix/');
/**
 * The location of the device images on the local filesystem
 */
$image->setImagesDirectory('/var/www/device_pix/');
/**
 * Get the source URL of the image (ex. '/device_pix/blackberry8310_ver1.gif')
 */
$image_src = $image->getImage();
if($image_src){
	// If and image exists, show it
	$image_html = sprintf('<img src="%s" border="0"/>',$image_src);
	echo $image_html;
}else{
	// If an image is not available, show a message
	echo "No image available";
}
?>
Personal tools