PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of andrei tataranu   Image dynamic resizer   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: example of use
Class: Image dynamic resizer
Resize an image keeping the aspect ratio
Author: By
Last change:
Date: 16 years ago
Size: 2,151 bytes
 

Contents

Class file image Download
<? session_start(); ?>
<?
require_once('cls_iresizer.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dynamic Image Resizer</title>
</head>

<body>

<?


$dimg
= new ImageResizer();

// -- original image: load from file
$dimg->loadImage("image.jpg");
// ---OR---
// provide a prevously loaded/created image:
// $dimg->setImage($img);

// retrieve the original image
$o_img = $dimg->getOriginal();
$dimg->resize(0,300);
$r_img = $dimg->getResult();
$dimg->setExactSizeResult(true,140,140,100);
$dimg->resize(300,300,0);
$r_img1 = $dimg->getResult();

// store the images in _SESSION for use by 'image.php'
ob_start();
   
imagejpeg($o_img);
   
$_SESSION['images']['orig_img']=ob_get_contents();
ob_end_clean();
ob_start();
   
imagejpeg($r_img);
   
$_SESSION['images']['res_img']=ob_get_contents();
ob_end_clean();
ob_start();
   
imagejpeg($r_img1);
   
$_SESSION['images']['res_img1']=ob_get_contents();
ob_end_clean();

?>

<table width="200" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td colspan="3" bgcolor="#eeeeee"><div align="center">Dynamic Auto Resizer Example </div></td>
  </tr>
  <tr>
    <td bgcolor="#eeeeee">original image:&nbsp;</td>
    <td align="center" bgcolor="#eeeeee"><img src="image.php?id=orig_img" /></td>
    <td bgcolor="#eeeeee">&nbsp;<? echo imagesx($o_img).'x'.imagesy($o_img); ?></td>
  </tr>
  <tr>
    <td bgcolor="#CCCCCC">resize(0,300):&nbsp;</td>
    <td align="center" bgcolor="#CCCCCC">&nbsp;<img src="image.php?id=res_img" /></td>
    <td bgcolor="#CCCCCC">&nbsp;<? echo imagesx($r_img).'x'.imagesy($r_img); ?></td>
  </tr>
  <tr>
    <td bgcolor="#EEEEEE">resize(300,300,0), exactSize:&nbsp;</td>
    <td align="center" bgcolor="#eeeeee">&nbsp;<img src="image.php?id=res_img1" /></td>
    <td bgcolor="#eeeeee">&nbsp;<? echo imagesx($r_img1).'x'.imagesy($r_img1); ?></td>
  </tr>
</table>

 
<br />
<br />
</body>
</html>