|
|
|
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 | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | PHP Random rss feeds - selects 49 random feeds from an unlimited list and displays them on your website. It's Ideal for those moments when you got 5 minutes and dont know which one of your feeds to read. Categories : PHP, Rich Site Summary (RSS), Arrays | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | Stock quotes from yahoo! Categories : PHP, Web Services, Arrays | | | A couple of functions that convert an IP address into its color code and not-color-code. Useful when viewing an apache log with a mysql result grouped by IP Categories : PHP, Graphics, Databases | | | PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside. Categories : PHP, Arrays, Variables | | | XML To Array Categories : PHP, PHP Classes, XML, Arrays | | | translate.php - Assocciative array example, passing a reference to a function. Categories : PHP, Arrays, Languages, Variables | | | Finds the median in an array of numbers - Can be used with a MySql database column read into an array Categories : PHP, Arrays, Databases, MySQL | |
|
|
|