1<?php
2//////////////////////////////////////////////////////////////
3//   phpThumb() by James Heinrich <info@silisoftware.com>   //
4//        available at http://phpthumb.sourceforge.net      //
5//         and/or https://github.com/JamesHeinrich/phpThumb //
6//////////////////////////////////////////////////////////////
7///                                                         //
8// phpThumb.demo.object.simple.php                          //
9// James Heinrich <info@silisoftware.com>                   //
10//                                                          //
11// Simplified example of how to use phpthumb.class.php as   //
12// an object -- please also see phpThumb.demo.object.php    //
13//                                                          //
14//////////////////////////////////////////////////////////////
15
16// Note: phpThumb.php is where the caching code is located, if
17//   you instantiate your own phpThumb() object that code is
18//   bypassed and it's up to you to handle the reading and
19//   writing of cached files, if appropriate.
20
21die('For security reasons, this demo is disabled by default. Please comment out line '.__LINE__.' in '.basename(__FILE__));
22
23require_once '../phpthumb.class.php';
24
25// create phpThumb object
26$phpThumb = new phpThumb();
27
28$thumbnail_width = 100;
29
30// set data source -- do this first, any settings must be made AFTER this call
31if (is_uploaded_file(@$_FILES['userfile']['tmp_name'])) {
32	$phpThumb->setSourceFilename($_FILES['userfile']['tmp_name']);
33	$output_filename = './thumbnails/'.basename($_FILES['userfile']['name']).'_'.$thumbnail_width.'.'.$phpThumb->config_output_format;
34} else {
35	$phpThumb->setSourceData(file_get_contents('..\images\disk.jpg'));
36	$output_filename = './thumbnails/disk_small.jpg';
37}
38
39// PLEASE NOTE:
40// You must set any relevant config settings here. The phpThumb
41// object mode does NOT pull any settings from phpThumb.config.php
42//$phpThumb->setParameter('config_document_root', '/home/groups/p/ph/phpthumb/htdocs/');
43//$phpThumb->setParameter('config_cache_directory', '/tmp/persistent/phpthumb/cache/');
44
45// set parameters (see "URL Parameters" in phpthumb.readme.txt)
46$phpThumb->setParameter('w', $thumbnail_width);
47//$phpThumb->setParameter('fltr', 'gam|1.2');
48//$phpThumb->setParameter('fltr', 'wmi|../watermark.jpg|C|75|20|20');
49
50// generate & output thumbnail
51if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
52	if ($phpThumb->RenderToFile($output_filename)) {
53		// do something on success
54		echo 'Successfully rendered to "'.$output_filename.'"';
55	} else {
56		// do something with debug/error messages
57		echo 'Failed:<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
58	}
59	$phpThumb->purgeTempFiles();
60} else {
61	// do something with debug/error messages
62	echo 'Failed:<pre>'.$phpThumb->fatalerror."\n\n".implode("\n\n", $phpThumb->debugmessages).'</pre>';
63}
64