TransPythia - Overview

TransPythia features a Transcoder that can apply a set of TranscodingAction to content. Each TranscodingAction. The library depends on the AskPythia library to extract the properties of the requesting device.

Code example

Let's have a look at a working code example that uses some of the existing TranscodingAction to adapt HTML content and the AskPythia implementation on top of WURFL to retrieve the requesting device properties.

// Prerequisites: Prepare AskPythia
$service = ServiceFactory::newService(
    array('wurfl_path'=>'[path to WURFL]'));
$evidence = $service->newHTTPEvidenceM($_SERVER);

// Step 1: Create the transcoder
$transcoder = new Transcoder($service);

// Step 2: Add needed transcoding actions
$trans = $transcoder->newTranscodingAction('ResizeIMG');

$trans = $transcoder->newTranscodingAction('DeletePopup');

$trans = $transcoder->newTranscodingAction('LinearTables');
$trans->setOption('layout', true);

// Step 3: Apply transcoder to HTML content
$adaptedContent = $transcoder->apply($content, $evidence);

The adapted content contains the result of the transcoding: tables are linearized if the device does not support them, popup windows are removed, and images are resized to fit the size of the device's screen.

Let's have a closer look at each of the three steps.

Step 1: Create the transcoder

A Transcoder is merely a container for TranscodingAction. The Service instance that must be used to access the DDR needs to be created beforehand. Transcoding actions will have access to the requesting device's properties through it.

Step 2: Initialize transcoding actions

The transcoding actions are described elsewhere. The set of transcoding actions to add to the transcoder depends on the type of content the transcoder will be applied to. A transcoding action that applies to CSS content must not be added to a transcoder that applies to HTML content.

Transcoding actions may rely on options that may be set through a call to the setOption method of the TranscodingAction class.

Transcoding actions should be created using the factory method of the transcoder to be granted access to the Service that should be used to retrieve the properties of the requesting device.

Step 3: Apply transcoding

When the Transcoder has been properly initialized, it can be applied to content for a particular requesting device described by some evidence.

The transcoder applies the transcoding actions one after the other in the order in which they were added to the transcoder and returns the adapted content.

Contact: François Daoust <>