If you are fed up of always manually manipulating the layout with images, try this code:
<?
$width=300; //size in pixel
$height=300; //size in pixel
$image="sample.jpg";
<img src="<? echo $image ?>" border="0" <? check_image($image) ?> >
?>
Include this function in your scripts:
<?
function check_image($image,$cfgMaxImgWidth,$cfgMaxImgHeight)
{
global $strNewImageSize,$cfgMaxImgWidth,$cfgMaxImgHeight;
$imageAttributes=$strNewImageSize="";
$imageAttributes=GetImageSize($image);
if($imageAttributes[0]>$cfgMaxImgWidth)
{
$factor=$imageAttributes[0]/$cfgMaxImgWidth;
$newImgWidth=$cfgMaxImgWidth;
$newImgHeight=round($imageAttributes[1]/$factor);
$strNewImageSize="width=$newImgWidth height=$newImgHeight";
}
elseif($imageAttributes[1]>$cfgMaxImgHeight)
{
$factor=$imageAttributes[1]/$cfgMaxImgHeight;
$newImgHeight=$cfgMaxImgHeight;
$newImgWidth=round($imageAttributes[0]/$factor);
$strNewImageSize="width=$newImgWidth height=$newImgHeight";
}
echo $strNewImageSize;
}
?>
What happens: the given image will be scaled either if it is too wide or too high or both, down
to the set values. It will be nicely scaled by maintaining the aspect ratio.
Enjoy
n-dee
How to display any array in several rows and columns of a table. Not just
in one column or in alternate rows. This example shows a nice color table
generated with PHP, but can be used with any array values(e.g. Database) Categories : Arrays , PHP , Miscellaneous , Beginner Guides , Graphics HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout. Categories : Graphics , Arrays , PHP , PHP Classes , Charts and Graphs Simple PHP Bar Graph using GD library Categories : PHP , GD image library , Graphics , Arrays This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given. Categories : PHP , Arrays , Graphics , Filesystem PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP , Graphics , GD image library , Beginner Guides PHP Array to Javascript Object Categories : PHP , Arrays , Java Script Line graphics generation library written in PHP + GD library (spanish comments) Categories : PHP , Graphics , GD image library This functions makes it easy to use session-variables known from ASP. With one Cookie the array "session" will save and restore from a db-record. In this version MySQL is used but it's should very easy to change Categories : PHP , Arrays , Cookies , MySQL , Databases Parse string to find sub-string between two arbitrary strings Categories : PHP , Strings , HTML and PHP , Arrays Diffusion-Limited Aggregation visualization Categories : PHP , Graphics , Algorithms , Math. A class to put get and post variables in hidden form
elements. Works on scalars, normal arrays, associative
arrays. Categories : Algorithms , Variables , Arrays , PHP , PHP Classes Can the word DO be used in arrays? Categories : Arrays , PHP , Strings This is a simple photo gallery that reads the image files from multiple directories, and generates a web page styled with CSS1. It opens single auto window to view and print a given image.
Categories : Graphics , Filesystem , PHP , Complete Programs This program implements hot link prevention in php. It is useful for webmasters who do not have access to the server at a level where they can control hot linking can still supply some type of hot link prevention for thier site by using php. Categories : PHP , Filesystem , Graphics , Content Management The simple counter with use MySql and gd. Categories : MySQL , HTTP , Graphics , PHP , Databases