| Thumbnail images in PHP |
| Written by Mohammad Dayyan |
| Friday, 30 January 2009 16:00 |
IntroductionAt times we need to change image size .Now I show you how we can do that by PHP. Using the Code
There is a function in the sorce code .
<?php
require_once("thumbnail.php");
thumbnail_image("source.jpg","320", "200", "");
?>
Above sample creats thumbnail.jpg in 320*200 image inside of source.jpg How does it workI got image information by getimagesize PHP function. $imgInfo = getimagesize($original_file_path); $imgExtension = ""; //extension of original image switch ($imgInfo[2]) { case 1: $imgExtension = ".gif"; break; case 2: $imgExtension = ".jpg"; break; case 3: $imgExtension = ".png"; break; } If $save_path equals "" then thumbnail file will be "thumbnail".$imgExtension
if ($save_path=="") $save_path = "thumbnail".$imgExtension ;
Getting width and height of original size and create an image object to creating thumbnail image
// Get new dimensions
list($width, $height) = getimagesize($original_file_path);
// Resample
$imageResample = imagecreatetruecolor($new_width, $new_height);
if ( $imgExtension == ".jpg" )
{
$image = imagecreatefromjpeg($original_file_path);
}
else if ( $imgExtension == ".gif" )
{
$image = imagecreatefromgif($original_file_path);
}
else if ( $imgExtension == ".png" )
{
$image = imagecreatefrompng($original_file_path);
}
imagecopyresampled($imageResample, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
Lastly creates a thumbnail image and save it
if ( $imgExtension == ".jpg" )
{
imagejpeg($imageResample, $save_path);
}
else if ( $imgExtension == ".gif" )
{
imagegif($imageResample, $save_path);
}
else if ( $imgExtension == ".png" )
{
imagepng($imageResample, $save_path);
}
Something wrong with this article? Report it |
| Last Updated on Friday, 06 February 2009 16:00 |
Recent Web Development Articles
Online Dating WebsitesI had some free time, and decided to create a 100% free dating website www.MatchElf.com as an experiment to see how long it would take me to write a fully functional, 100% free dating website, and I quickly learned th... ASP.NET | Saturday, 31 January 2009 |
Hack to enforce the cache of an XmlDataSource to invalidateWe often use the XmlDataSource control together with the TreeView control. ASP.NET | Saturday, 31 January 2009 |
Nine ASP.NET Site Navigation Problem Solutions: Part 1Find out how to use ASP.NET 2.0"s site navigation controls to not only make building site navigation displays simple, but also solve real-world problems, such as hiding selected pages, or displaying "breadcrumbs." ASP.NET | Saturday, 31 January 2009 |
AutoSearch SELECT tagIf you spend any time surfing the web you will find <select> lists. In all cases Ive encountered the default single character searches are used to help you "quickly" find the list item you want. As an example, to reach North Carolina in a list of states you would ... JavaScript | Saturday, 31 January 2009 |
AntiHistoDo you share a computer with someone? Have you ever visited a URL that youre not exactly proud of? Wish you could delete it from the Internet Explorer history list? Well sit back and crack open a beer, because let me ... General Web Development | Saturday, 31 January 2009 |
Thumbnail images in PHPAt times we need to change image size . Now I show you how we can do that by PHP. Using the Code There is a function in the sorce code . Now I describe it : function thumbnail_image($original_f... General Web Development | Saturday, 31 January 2009 |
XML Web Services: Just Another Data Tier?Many developers build a Web site and later, add XML Web services as separate projects, resulting in two code bases. This article shows you how to reuse XML Web service to provide data to your own applications. ASP.NET | Friday, 30 January 2009 |
An ISAPI project to show framesGeneral Web Development | Friday, 30 January 2009 |
Easily Work With Differing Time Zones In An ASP.NET 3.5 ApplicationWhen working with ASP.NET applications, time zones are often a problem when dealing with DateTime structures. There are two different common scenarios that a developer is likely to encounter. The first is that you are placing the application on a hosted server that is... ASP.NET | Thursday, 29 January 2009 |
IIS TimerFirst of all I would like to apologize for my English. ASP.NET | Thursday, 29 January 2009 |
WinFiltDiff, a utility to filter out unimportant source-differencesWinFiltDiff 1.1 is a tool that allows you to filter the input to WinDiff so WinDiff does not clutter its output with files you do not care about. You can use WinFiltDiff to suppress WinDiff entries about intermediate files like .obj files. It can suppress differences due to... General Web Development | Thursday, 29 January 2009 |
Simple ASP.NET Session Management FrameworkFor a project of my former employer, I’ve run into a problem of losing Session information after communication with other applications on different domains. My ASP.NET application was communicating via hidden-fields through a POST on a Java-Servlet and PHP pages. These page... General Web Development | Thursday, 29 January 2009 |
Working with cookiesASP.NET | Wednesday, 28 January 2009 |
How to display a totals line in the GridView footerThis article explains how to display a totals line in the GridView footer. First bind a XML-file to the GridView. Here is the code for this task: ASP.NET | Wednesday, 28 January 2009 |
ASP.NET MVC : Create Toolbar ControlMany applications need a Toolbar kind of functionality including application created using ASP.net MVC . I thought of epxerimenting this with ASP.net MVC. Background Think about a application (ex CRM) with different models (ex Customer, O... ASP.NET | Wednesday, 28 January 2009 |
A DropDownList for U.S. States/Canadian Provinces and CountriesMy task was to create a simple DropDownList containing U.S. States and Canadian Provinces that could be reused easily. The requirements were that it should be entirely self-contained and should operate exactly like any other DropDownList. ASP.NET | Wednesday, 28 January 2009 |
Simple, accessible drop down menuMost of the drop down menus you find on the web are not free and the ones which are free have a lot of disadvantages. They may disappear too quickly, have hardcoded layouts, be time expensive to impliment and so on. I have had some bad experiences and therefore I decided to write ... JavaScript | Wednesday, 28 January 2009 |
Introduction to NLogOnce upon a time, when there were no debuggers in the world and software was mostly console-based, programmers used to output tracing messages using printf() ... General Web Development | Wednesday, 28 January 2009 |
master pages - The ASP.net 2.0 wayOne of the highlights of ASP.net 2.0 has been the ‘master pages’ feature. Master Pages feature is one of the most power features that many develo... ASP.NET | Tuesday, 27 January 2009 |
Top 10 Security Vulnerabilities in .NET Configuration FilesDevelopers often concentrate on writing secure code but leave security vulnerabilities in application configuration files. Discover the most common configuration security problems—and how to avoid them. ASP.NET | Tuesday, 27 January 2009 |
|
More in: PHP, ASP.NET, Perl, Python, JavaScript, Ruby, AJAX, Joomla!, HTML & CSS, General Web Development |
|
Latest Articles
- AntiHisto
- Thumbnail images in PHP
- Online Dating Websites
- Hack to enforce the cache of an XmlDataSource to invalidate
- AutoSearch SELECT tag
- Nine ASP.NET Site Navigation Problem Solutions: Part 1
- Enhanced rich edit control
- CheckListBox based on ListBox that supports ReadOnly
- Introduction to COM - What It Is and How to Use It.
- Introduction to the Validation Application Block

