WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple way of scaling any image to fit either given width or height.
Categories : PHP, Graphics, Arrays Update Picture
Andy Krause
Date : Dec 05th 2000
Grade : 1 of 5 (graded 1 times)
Viewed : 3895
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Andy Krause
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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