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 : PHP Image Compression using GD library
Categories : PHP, Compression, GD image library, Graphics Click here to Update Your Picture
Suraj Thapaliya
Date : Mar 06th 2007
Grade : 1 of 5 (graded 2 times)
Viewed : 6331
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Suraj Thapaliya
Action : Grade This Code Example
Tools : My Examples List

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

The script is used for image compression such as photo gallery and the script automatically compress the image base on the given dimension. it will automatically calculate the landscape image or portrait image. This script is very much useful to those who doesn't want to use other image procession application

<?php
/*
Owner Name: Suraj Thapaliya
Email: surajthapaliya at gmail.com


The script is used for image compression such as photo gallery and the script automatically compress the image base on the given dimension. it will automatically calculate the landscape image or portrait image

before use this code you must have to enable your gd library

If this script is useful to anyone please send me the mail   

*/
$imgfile="photo/myson.jpg"; // The Source of your image file
function imageCompression($imgfile="",$thumbsize=0,$savePath=NULL) {
    if(
$savePath==NULL) {
       
header('Content-type: image/jpeg');
       
/* To display the image in browser
       
        */
       
   
}
    list(
$width,$height)=getimagesize($imgfile);
   
/* The width and the height of the image also the getimagesize retrieve other information as well   */
   
echo $width;
    echo
$height;
   
$imgratio=$width/$height
   
/*
    To compress the image we will calculate the ration 
    For eg. if the image width=700 and the height = 921 then the ration is 0.77...
    if means the image must be compression from its height and the width is based on its height
    so the newheight = thumbsize and the newwidth is thumbsize*0.77...
    */
   
   
if($imgratio>1) {
       
$newwidth=$thumbsize;
       
$newheight=$thumbsize/$imgratio;
    } else {
       
$newheight=$thumbsize;       
       
$newwidth=$thumbsize*$imgratio;
    }
   
   
$thumb=imagecreatetruecolor($newwidth,$newheight); // Making a new true color image
   
$source=imagecreatefromjpeg($imgfile); // Now it will create a new image from the source
   
imagecopyresampled($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height);  // Copy and resize the image
   
imagejpeg($thumb,$savePath,100);
   
/*
    Out put of image 
    if the $savePath is null then it will display the image in the browser
    */
   
imagedestroy($thumb);
   
/*
        Destroy the image
    */
   
}
imageCompression($imgfile,150,"a.jpg");
?>



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
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Line graphics generation library written in PHP + GD library (spanish comments)
Categories : PHP, Graphics, GD image library
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
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
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
Generate image with random number (CAPTCHA)
Categories : PHP, GD image library, Graphics, Security
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP