WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 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
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

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 : Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
Moiz Sitabkhan
Date : May 07th 2007
Grade : 3 of 5 (graded 12 times)
Viewed : 23118
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Moiz Sitabkhan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

This function accepts 5 parameters. The first 2 are necessary. The first parameter accepts the file location along with the filename which needs to be resized. 2nd parameter accepts the maximum width. the picture is resized to a maximum of this width and reduces the height proportionatly. The 4th parameter accepts a new filename. ( if you wish to rename the file or change its location after its been resized so as not to harm the original file. )

<?php
function resizeImage($filename,$max_width,$max_height='',$newfilename="",$withSampling=true)
{
    if(
$newfilename=="")
       
$newfilename=$filename;
   
// Get new sizes
   
list($width, $height) = getimagesize($filename);
   
   
//-- dont resize if the width of the image is smaller or equal than the new size.
   
if($width<=$max_width)
       
$max_width=$width;
       
   
$percent = $max_width/$width;
   
   
$newwidth = $width * $percent;
    if(
$max_height=='') {
       
$newheight = $height * $percent;
    } else
       
$newheight = $max_height;
   
   
// Load
   
$thumb = imagecreatetruecolor($newwidth, $newheight);
   
$ext = strtolower(getExtension($filename));
   
    if(
$ext=='jpg' || $ext=='jpeg')
       
$source = imagecreatefromjpeg($filename);
    if(
$ext=='gif')
       
$source = imagecreatefromgif($filename);
    if(
$ext=='png')
       
$source = imagecreatefrompng($filename);
   
   
// Resize
   
if($withSampling)
       
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    else   
       
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
       
   
// Output
   
if($ext=='jpg' || $ext=='jpeg')
        return
imagejpeg($thumb,$newfilename);
    if(
$ext=='gif')
        return
imagegif($thumb,$newfilename);
    if(
$ext=='png')
        return
imagepng($thumb,$newfilename);
}
?>



crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
Generate image with random number (CAPTCHA)
Categories : PHP, GD image library, Graphics, Security
Create a Thumbnail Using PHP, GD and Exif
Categories : PHP, Graphics, Exif, GD image library
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
Add a text description to an image. The text is not created over the image but rather creates a new, higher image. The upper part is the original image and the lower is the text. Text is wrapped at the end of line, the number of rows is adjustable.
Categories : PHP, GD image library, Graphics
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
A captcha image allows you to prevent spam posting when users reload the page and stop bots from submitting forms automatically. This version allows you to use your own fonts (.ttf) to show the text.
Categories : PHP, Security, Graphics, GD image library
Simple PHP Bar Graph using GD library
Categories : PHP, GD image library, Graphics, Arrays
EasyPhpThumbnail Class - The EasyPhpThumbnail class allows you to generate thumbnails and handle image manipulation for GIF, JPG and PNG on-the-fly.
Categories : PHP, PHP Classes, Object Oriented, Graphics, GD image library
PHP Image Compression using GD library
Categories : PHP, Compression, GD image library, Graphics
Line graphics generation library written in PHP + GD library (spanish comments)
Categories : PHP, Graphics, GD image library
 mmx97 mmx97 wrote :1760
hello Moiz Sitabkhan 
thank you for this code 
1. but can you give us an Example by file include image resize function with images folder called images 

2. in this code 

  if($ext=='jpg' || $ext=='jpeg') 
        $source = imagecreatefromjpeg($filename); 
    if($ext=='gif') 
        $source = imagecreatefromgif($filename); 
    if($ext=='png') 
        $source = imagecreatefrompng($filename); 

what about bmp file ext?!!

thank you