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 : Easy to use image resizer and resampler (get a resized resampled copy of an image)
Categories : PHP, Graphics, GD image library Click here to Update Your Picture
Khair-ed Din Husseini
Date : Mar 26th 2005
Grade : 4 of 5 (graded 4 times)
Viewed : 3284
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Khair-ed Din Husseini
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

a very easy to use function to get a resized resampled copy of an image. the copy can be saved to a server or put out directly to the browser. If you want to put the image directly out to serve you will have to put proper header information in the calling page.

NOTE: Input can only be jpg.
PNG will be added soon

Note: This script requires :
GD 2.0.1 or later
PHP >= 4.0.6


<?php
/**
* @return Void
* @param Integer $cp_bigs
* @param String $picdir
* @param String $picname
* @param String/Boolean $copydir
* @desc Makes a resized and resampled scaled copy into specified directory. Returns false if fails.
*/
function make_res_copy($cp_bigs, $picdir, $picname, $copydir)
    {
       
//check if file has a jpg (jpeg) extension
       
if(strstr(strtolower($picname), ".jpg") or strstr(strtolower($picname), ".jpeg"))
        {
                if(
strstr(strtolower($picname), ".jpg") or strstr(strtolower($picname), ".jpeg"))
                    {
                       
$im  = ImageCreateFromJPEG($picdir . "/" . $picname);
                    }
               
               
//get the original image size   
               
$size = getImageSize($picdir . "/" . $picname);
                       
               
$dstX = 0;
               
$dstY = 0;
               
$srcX = 0;
               
$srcY = 0;
               
               
//decide wether picture is horizontally or vertically aligned
                //-->ofcourse if the picture is rectangular all sides of the
                //-->copy will be equal
               
if($size[0] < $size[1])
                    {
                       
$ratio = $size[1]/$cp_bigs;
                       
$dstW = $size[0] / $ratio;
                       
$dstH = $cp_bigs;
                    }
                elseif(
$size[0] == $size[1])
                    {   
                       
$dstW = $cp_bigs;
                       
$dstH = $cp_bigs;
                    }
                else
                    {
                       
$ratio = $size[0]/$cp_bigs;
                       
$dstW = $cp_bigs;
                       
$dstH = $size[1] / $ratio;
                    }
       
               
               
$srcW = $size[0];
               
$srcH = $size[1];
       
               
$imdst = ImageCreateTruecolor($dstW, $dstH);
                               
               
ImageCopyResampled($imdst, $im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
                if(
$copydir)
                   
ImageJPEG($imdst, $copydir . "/" . $picname);
                else
                   
ImageJPEG($imdst);
               
        }
       
    }
?>



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
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
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
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
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
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
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
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
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
PHP Image Compression using GD library
Categories : PHP, Compression, GD image library, Graphics
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics