Banner sizing function
This function allows you to input your image , the percentage you wish the width to be displayed at and the percentage you wish the height to be displayed at .
The syntax to call the function is ResizeImage("image.gif" , width percent , height percent);
In this example we have put the function in a seperate file called imageresize.php
Code :
Lets look at the function code
<?php
function ResizeImage($image ,$width ,$height)
{
//image resizer by myscripting
//get the size of the original
$size = GetImageSize($image);
//divide the width / height percentage by 100
$new_width = 100 / $width;
$new_height = 100 / $height;
//store the resized dimensions in a variable
$sizeh = $size[1]/ $new_height;
$sizew= $size[0]/ $new_width;
//display the new resized image
$new_image = "<img src = \"$image\" height=\"$sizeh\" width =\"$sizew\">";
echo $new_image;
}
?>
Here is how we call this script with some examples .
<?php
require("imageresize.php");
//this reduces the image
ResizeImage("1.gif",50,50);
echo "<br>";
//we can increase an image as well
ResizeImage("1.gif",150,150);
?>
Examples :
Warning: require(imageresize.php) [
function.require]: failed to open stream: No such file or directory in
/home/beginne/public_html/resizefunction.php on line
213
Warning: require(imageresize.php) [
function.require]: failed to open stream: No such file or directory in
/home/beginne/public_html/resizefunction.php on line
213
Fatal error: require() [
function.require]: Failed opening required 'imageresize.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in
/home/beginne/public_html/resizefunction.php on line
213