Php > Graphics
Resizing a displayed image without GD
Resizing a displayed image without GD // Resizer.php // I wrote this function so that I could display thumbnails of pictures users // uploaded without having to actually modify the file. This function will return // a height and width to put in your
tag that will be proportionate to each // other. Again, the actual file is not modified, and GD is NOT required. Modifying // this to your needs should be pretty simple, but this will give you an idea on // how to do it. $pic = "image.jpg"; // This is the name of the image to modify $dimensions = resize($pic); // Here we call our function to get new height/width for the image. // Print it all our echo "\n\n"; echo "
\n"; echo "\n"; function resize($v_pic) { // This is our main function $largestside = 120; // This is the size of the LARGEST SIZE we want either our width or height to be $size = GetImageSize ("$v_pic"); // Get the actual width/height of the image... $width = $size[0]; $height = $size[1]; if ($width == $height) { // If the height == width $dimensions[0] = $largestside; // Assign both width and height the value of $largestsize $dimensions[1] = $largestside; } elseif ($width > $height) { // If the width is greater than the height $divisor = $width / $largestside; $height = $height / $divisor; $dimensions[0] = $largestsize; // Assign $largestsize to width $dimensions[1] = intval ($height); // and assign $height a proportionate value to $height } elseif ($width < $height) { // If width is less than height $divisor = $height / 120; $width = $width / $divisor; $dimensions[0] = intval ($width); // Set width to be proportionate to height $dimensions[1] = 120; // Set height to be $largestsize } return $dimensions; } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage