<?php
/**
 * QThumbService.php
 * 
 * @author Roy Sindre Norangshol <norrs 'at' tihlde.org>
 * @version Creation Date: Apr 2, 2008
 */

/**
 * QThumbService.php class
 * 
 * Uses Thumbnail class by Ian Selby
 * Check http://www.gen-x-design.com/demos/thumbnailer/ :-)
 * 
 * Place <service id="thumb" class="QThumbService"></service> in application.xml to use.
 * Demo: http://localhost/?thumb=themes/Basic/some_cool_picture&height=0&width=400 (resizes automagically by width)
 * Demo: $this->getRequest()->constructUrl('thumb', 'themes/Basic/some_cool_picture.png', array('height' => 0, 'width => 350))
 * 
 * Properties
 * -
 * 
 * @author Roy Sindre Norangshol <norrs 'at' tihlde.org>
 * @version Creation Date: Apr 2, 2008
 * 
 * Modifications:
 */
class QThumbService extends TService{
	/**
	 * Runs the service.
	 */
	public function run(){
		include_once('thumbnail.inc.php');
		$file = null;
		// get file key from request service parameter
		$file= $this->getRequest()->getServiceParameter();

		if ($file && isset($_GET['width']) && isset($_GET['height'])){
			$thumb = new Thumbnail($file);
			$thumb->resize($_GET['width'],$_GET['height']);
			$thumb->show();
			exit;
		}			
		else 
			throw new THttpException(404,'thumbservice_file_invalid_or_height_or_width_not_set',$fileKey);
		
	}
}
?>