How to create a thumbnail-PHP code

To create a thumbnail, you pass the function PIPHP_MakeThumbnail()a GD image object
and the maximum value of the greater dimension for the thumbnail. For example, the
following code loads in the image in test.jpgusing the imagecreatefromjpeg()function,
and then passes it to the plug-in, along with a maximum dimension of 100. The function
then returns the new thumbnail to the string variable $thumb, which is then saved to the file
thumb.jpgusing the imagejpeg()function.

$image = imagecreatefromjpeg("test.jpg");
$thumb = PIPHP_MakeThumbnail($image, 100);
imagejpeg($thumb, "thumb.jpg");
You can also output the thumbnail straight to the browser by first sending the correct
header, like this:
$image = imagecreatefromjpeg("test.jpg");
header("Content-type: image/jpeg");
imagejpeg(PIPHP_MakeThumbnail($image, 100));

The PHP GD library is so powerful that it can perform a variety of image manipulations you
would normally only find in a graphics program. In fact, you could probably build quite an
advanced image editor using them.
<?php
function PIPHP_MakeThumbnail($image, $max)
{
$thumbw = $w = imagesx($image);
$thumbh = $h = imagesy($image);
if ($w > $h && $max < $w)
{
$thumbh = $max / $w * $h;
$thumbw = $max;
}
elseif ($h > $w && $max < $h)
{
$thumbw = $max / $h * $w;
$thumbh = $max;
}
elseif ($max < $w)
{
$thumbw = $thumbh = $max;
}
return PIPHP_ImageResize($image, $thumbw, $thumbh);
}
?>

To perform an Edge Detect transformation on a file called photo.jpg,
you could use the following code, which will load a GD image object using the
imagecreatefromjpeg()function, and save the transformed image with the function
imagejpeg()
<?php
function PIPHP_ImageAlter($image, $effect)
{
switch($effect)
{
case 1: imageconvolution($image, array(array(-1, -1, -1),
array(-1, 16, -1), array(-1, -1, -1)), 8, 0);
break;
case 2: imagefilter($image,
IMG_FILTER_GAUSSIAN_BLUR); break;
case 3: imagefilter($image,
IMG_FILTER_BRIGHTNESS, 20); break;
case 4: imagefilter($image,
IMG_FILTER_BRIGHTNESS, -20); break;
case 5: imagefilter($image,
IMG_FILTER_CONTRAST, -20); break;
case 6: imagefilter($image,
IMG_FILTER_CONTRAST, 20); break;
case 7: imagefilter($image,
IMG_FILTER_GRAYSCALE); break;
case 8: imagefilter($image,
IMG_FILTER_NEGATE); break;
case 9: imagefilter($image,
IMG_FILTER_COLORIZE, 128, 0, 0, 50); break;
C h a p t e r  4 :  I m a g e  H a n d l i n g  71   C h a p t e r  4 :  I m a g e  H a n d l i n g  71
case 10: imagefilter($image,
IMG_FILTER_COLORIZE, 0, 128, 0, 50); break;
case 11: imagefilter($image,
IMG_FILTER_COLORIZE, 0, 0, 128, 50); break;
case 12: imagefilter($image,
IMG_FILTER_EDGEDETECT); break;
case 13: imagefilter($image,
IMG_FILTER_EMBOSS); break;
case 14: imagefilter($image,
IMG_FILTER_MEAN_REMOVAL); break;
}
return $image;
}
?>

PHP Functions
Php tutorial - imagemagick
php.ini Basics
PHP Sessions
Cookies Versus Sessions
PHP Web-Related Variables
PHP ERRORS
maximum size of a file uploaded
Php Image upload
php file_get_contents
MySQL Data on the Web
What are GET and POST
php and pdf
$_ENV and $_SERVER
PEAR with php
SELECTING DATA PHP
prevent hijacking with PHP
LAMP
PHP MySQL Functions
PHP Zip File Functions
Substrings PHP
PHP Variable names
PHP magic methods
How to get current session id
Add variables into a session
$_GET , $_POST,$_COOKIE
different tables present in mysql
PHP CURL
php Sessions page
PHP-sorting an array
PHP-count the elements of array
Operators for If/Else Statements
PHP file uploading code
PHP global variables
Testing working using phpinfo
PHP Code for a Valid Number
PHP-Associative Arrays
PHP mvc tutorial
PHP get_meta_tags-Extracts
difference between print and echo
PHP best tutorial-PHP variables
Reading DOC file in PHP
PHP interview questions
convert time PHP
PHP implode array elements
header function-PHP
PHP-Renaming Files Directories
PHP Classes
in_array function in PHP
keep your session secure PHP
Web Application with PHP
What is SQL Injection
PHP-extract part of a string
PHP urlencode
PHP- know browser properties
PHP- Extracting Substrings
Checking Variable Values /Types
PHP-best 20 Open Source cms
IP AddressPHP
PHP-Scope Resolution Operator
how create new instance of object
how eliminate an object
PHP- ob_start
XML file using the DOM API
PHP- MVC
PHP- CAPTCHA
PHP- Position of a Value in an Array
PHP-Mail Functions
PHP-difference include vs require
calculate the sum of values in an array
PHP-total number of rows
Show unique records mysql
MySQL Triggers
MySQL data directory
MySQL Subqueries
PHP- Networking Functions
PHP- Operators
Restore database
Conditional Functions mysql
PHP-function overloading
Friend function
mysql_connect /mysql_pconnect
PHP-Error Control Operators
what is IMAP
Apache-Specific Functions
Send Email from a PHP Script
SQL inherently
WAMP, MAMP, LAMP
Php tutorial-SYMBOLS
Table Types-MySQL
PHP-Encryption data management
PHP Array
Running MySQL on Windows
Maximum Performance MySQL
XML-RPC
PHP-static variables
Advanced Database Techniques
FTP
Codeigniter
Apache Pool Size
Why NoSQL
MySQL Server Performance
Database software
SQL Interview Answers
PHP Redirect
PHP Interview Questions with Answers
Advanced PHP