Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e617287b13
Fetching contributors…

Cannot retrieve contributors at this time

92 lines (84 sloc) 4.72 kb
<?php // -*- mode:sgml; tab-width:4; indent-tabs-mode:nil; -*-?>
<!DOCTYPE html>
<html>
<head>
<title>Samples</title>
<style>
BODY { font: 16px Palatino Linotype, Book Antiqua, Palatino, serif}
STRONG { margin-bottom: .5em; display: block }
H1 { margin: 0; }
UL { margin: 0; padding: 0 }
LI { list-style-type: none; margin-left: 0 }
PRE { font: 11px monospace; text-align: left;margin-left: 10px }
.slide { background-color: #eeeeee; padding: .5em; border: 1px solid #cccccc; margin-bottom: 1em; }
FOOTER { clear: both; font-size: 77%; font-style: italic }
</style>
</head>
<body>
<h1>Resizer.php Demo</h1>
<p>The examples on this page show a few different ways of configuring Resizer to meet various requirements.</p>
<?php include('Resizer.php') ?>
<?php $r = new Resizer(array('cache_path'=>'cache', 'base_url'=>'cache', 'verbose'=>true, 'skip_cache'=>false)); ?>
<?php $r->checkEnvironment() ?>
<?php $image = (empty($_GET['image']))? 'sailboat.jpg' : preg_replace("/[^\w.\-_]/", null, $_GET['image']) ?>
<?php $args = array('s'=>'sample-images/' . $image, 'w'=>100, 'h'=>100) ?>
<div class="slide">
<strong>Source Image</strong>
<ul>
<li><a href="<?php print $args['s'] ?>"><?php print $args['s'] ?></a></li>
<?php $dimensions = getimagesize($args['s']); ?>
<li>Dimensions: <?php print implode(array_slice($dimensions, 0, 2), 'x') ?></li>
<li>Aspect ratio: <?php print round($dimensions[0]/$dimensions[1], 2) ?></li>
</ul>
Switch to: <a href="?image=blake.jpg">blake.jpg</a>
</div>
<div class="slide">
<strong>Example 1</strong>
<p>Goal: Shrink the source to 100px wide, preserving the aspect ratio.</p>
<?php $example = $args ?>
<?php $example['w'] = 100; unset($example['h']); ?>
<?php $r->setArgs($example); ?>
<?php list($path, $width, $height) = $r->resize(); ?>
<img src="<?php print $path ?>" width="<?php print $width ?>" height="<?php print $height ?>" />
<ul>
<?php $dimensions = getimagesize($path); ?>
<li>Dimensions: <?php print implode(array_slice($dimensions, 0, 2), 'x') ?></li>
<li>Aspect ratio: <?php print round($dimensions[0]/$dimensions[1], 2) ?></li>
</ul>
<?php print "<pre>" . $r->getMessages() . "</pre>"; ?>
</div>
<div class="slide">
<strong>Example 2</strong>
<p>Goal: Shrink the source to 100px tall, preserving the aspect ratio.</p>
<?php $example = $args ?>
<?php $example['h'] = 100; unset($example['w']); ?>
<?php $r->setArgs($example); ?>
<?php list($path, $width, $height) = $r->resize(); ?>
<img src="<?php print $path ?>" width="<?php print $width ?>" height="<?php print $height ?>" />
<ul>
<?php $dimensions = getimagesize($path); ?>
<li>Dimensions: <?php print implode(array_slice($dimensions, 0, 2), 'x') ?></li>
<li>Aspect ratio: <?php print round($dimensions[0]/$dimensions[1], 2) ?></li>
</ul>
<?php print "<pre>" . $r->getMessages() . "</pre>"; ?>
</div>
<div class="slide">
<strong>Example 3</strong>
<p>Goal: Shrink the source to 350px wide by 400px tall (changing the aspect ratio) without cropping. Fill the extra space with black.</p>
<?php $example = $args ?>
<?php $example['w'] = 350; $example['h'] = 400; $example['bg'] = "0,0,0" ?>
<?php $r->setArgs($example); ?>
<?php list($path, $width, $height) = $r->resize(); ?>
<img src="<?php print $path ?>" width="<?php print $width ?>" height="<?php print $height ?>" />
<ul>
<?php $dimensions = getimagesize($path); ?>
<li>Final aspect ratio: <?php print round($dimensions[0]/$dimensions[1], 2) ?></li>
</ul>
<?php print "<pre>" . $r->getMessages() . "</pre>"; ?>
</div>
<footer>
<p>The file sample-iamges/sailboat.jpg is courtesy of Bill Lovett</p>
<p>The file sample-images/blake.jpg is courtesy of <a href="http://commons.wikimedia.org/wiki/File:William_Blake_by_Thomas_Phillips_-_cropped_and_downsized.jpg">Wikimedia Commons</a>.</p>
</footer>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.