Web Components Factory
Article Base
Author Options
New account
Read articles
Manage Articles
Submit Category
Terms of service

Client Products
Calendar
Time Selector
Text Link
Marks System
Menu
Menu Bar

Server Products
Sitemap Gen BETA
Photo Viewer
Poll Builder
Counter
Guest Book
Where am i?

LinkExchange
Directory
Link Exchange


My Collections
Description
ScreenShots
Download
Buy
Register

We received 388027 visits from 14643 distinct visitors, since 04-08-2007
From:
United States2164
China405
India367
Germany332
United Kingdom250
Canada190
Korea, Republic of182
Portugal166
Sweden137
France136
Romania123
Netherlands109
Spain98
Malaysia94
Russian Federation86
Italy83
Brazil82
Australia71
Philippines71
Turkey48
Rest of world: 9449
 

View Article Base
 
Serving 501 articles.
Articles > PHP (Programming Languages) > How to create a complete set of thumbnail images, based on a folder path, and display the created content in PHP

How to create a complete set of thumbnail images, based on a folder path, and display the created content in PHP
Created on 2008-09-29 16:24:10Nb. of Hits: 586Rating:  (over 3 votes).


Introduction

If you have a folder with images and want to show those images on your website, you will probably think about showing thumbnails of each of them. This way you will be able to better organize your content and minimize the download time on the page by considerably reducing the size of the images. Additionaly, the user will be able to see the full size image by clicking on the thumbnail picture.

Getting all images from a specific folder

We should be able to retrieve every image from a specific folder by calling the following functions:

First we check for every files in the folder if they are pictures. The $file array should contain every pictures within the $path folder.

Dimensionning and drawing the thumbnail image

The challenge in thumbnail dimensioning can be summarize in one question: How will I do to reduce picture, with different sizes, into the same pattern? To answer this question, you will have to consider some factors.

  • An easy way would be to reduce the images with a constant factor for both width and height for each image. For instance, if you want to display an image "image1.gif" with 260px width and 400px height reduced by factor 5, you can do that:



    Real size image:
    Reduced image:

  • The problem is if you do that for a lot of different images, you page will still have to load the full images size. if you need to display 30 thumbnails on a page, each image having 500k, the total size of the page will be 15mb! Avoiding loading and reducing the full image by using IMG tags properties width and height, helps your webpage to load faster. For this, you will need to create a new reduced image of the real one.

    The solution is to create a reduced copy for each image. To be even more performant, the copy will be done only once, and the reduced images will be stored on the server and accessed like the original one.

  • If you want to show many thumbnails on the same page, like a mosaic, you will also have to consider a standard dimension for each thumbnail image so that they can look harmonious within the same shape. We will call this shape, the thumbnail pattern. Using a reduction factor to achieve that, is not a good idea, since if you use different size images, you would get different sized thumbnails

    Building the PHP coding that will allow your thumbnails to have a standard size (with maximum height or maximum width) in which each thumbnail image will fit is quite easy. It's like reducing the image until it fits in the thumbnail pattern!

    The thumbnail pattern dimensions should be considered as a rectangle where the thumbnail image should fit:



    At this point we are able to get the dimensions of the thumbnail picture $width and $height considering the maximum thumbnail size $thumbwidth and $thumbheight and we can show the thumbnail image:


    Putting the code in a function we can have:

Showing the thumbnail picture instead of the original picture

The following function's goal is to retrieve the thumbnail image according to the original image, and create it if it does not exists or the thumbnail pattern size has changed.
To do that, we only need to have the original image file and its dimensions and the previously calculated thumbnail dimensions. If the thumbnail does not exist yet, or, if it exists, but its dimensions are different from the previous calculated one, then a new thumbnail will be created at the location defined by:

original image: path / last_folder / imagename . extension
thumbnail image: path / last_folder / thb_last_folder / imagename . extension

For instance: the thumbnail image for /images/stamps/mystamp.gif is located at /images/stamps/thb_stamps/mystamp.gif

Coding the function:

Creating the thumbnail image (if it doesn't exist yet)

The following function will verify the existence of the thumbnail and if it exist, erase it. Then according to the type of the original picture, it will create a new image with smaller dimensions.

Calling the main functions

Sample

Check this link out.

History

2008-09-29: First version

David Domingues - David Domingues is a professional IT analyst.
 
[Back]
 
Rate this article
Brilliant
Very good
Good
Average
Bad
Null
 
[Back]
 
Comments
You should login in order to register your comments.
 
[Back]
 
 
More articles from this author
Falling image from the top of the screen with 780 hit(s) and rating 3.67/5 over 3 votes.
Some practice used to promote your site. Ethical or not... with 336 hit(s) and rating 4.75/5 over 4 votes.
Multi-language country combobox with 882 hit(s) and rating 4.57/5 over 7 votes.
Dynamise image behaviour with Javascript with 819 hit(s) and no rating yet
Simple Ajax Tutorial - Updating part of your form without reloading all with 807 hit(s) and rating 0/5 over 1 votes.
How to build a dynamic select field with 452 hit(s) and no rating yet
How to create a simple Database Access Layer (DBAL) with 573 hit(s) and no rating yet
How to divide query results into various pages. The navigation paginator class in PHP with 744 hit(s) and rating 5/5 over 4 votes.

 

Read our last 20 Articles
 
From author Adriana Noton in category Software>Presentation
The Many Choices Of Software Programs
Whether you are a teacher, a scientist, or a secretary, there are software programs available that will make your life easier.
 
From author AJ Handley in category Software>Presentation
Do I Really Need A Project Manager?
Each project has unique specifications that are bespoke to its requirements, therefore you an only make the decision of whether or not to hire a Project Manager to help implement the necessary steps to put your plans into place. To help with the decision we advise you to take into account your project time scales, team size, specification, resources and your suitability to the task.
 
From author Ben Sparks in category Software>Presentation
Why You Should Use A Find People Email Address Service
The number of people that rely on old fashioned methods for communication is dwindling each year. Now almost all of us have email addresses. Email has allowed society a far simpler method of contacting each other than was previously possible. But email is not without risk. There are many dangers that lurk within email. For this reason it is wise to use a trusted find people email address service.
 
From author George Pearson Shearsmith in category General Web Marketing>Search Engine Optimization
Search Engine Rank Reporting Software Can Help Your Website
If you have launched a website, then you should know that it is very important that you get it listed on various search engines. If you do not get traffic to your site, you cannot possibly earn any profits from it. People have to be able to find your site or there is really no point in having one. There are many ways in which search engine rank reporting software can benefit you. It helps you keep track of where your site ranks on such engines.
 
From author Joe Thomas in category Software>Training
Excel VBA training Can Take Your Excel Usage To The Next Level
Almost all computer users know Microsoft Excel to some degree and most are aware of macros and VBA. However, the vast majority shy away from VBA assuming it to be the preserve of Excel gurus and professional programmers. Nothing could be further from the truth: having Excel VBA training is a natural progression for anyone who knows Excel well and want to take their knowledge to the next level.
 
From author Jason Kendall in category Programming Languages>C# development
C Programming Career Courses At Home - Update
With an abundance of computer courses on offer these days, it's best to take advice from a training organisation who can guide you on the right one for you. Reputable organisations will familiarise you with the differing job options that might suit you, in advance of recommending a training path that will give you the knowledge you need.
 
From author in category Internet>Forums
Website + Google adsense account @3000
Instant Cash Machine is nothing but Internet's best Free Income generating opportunity. This Income opportunity is offered by Google Adsense. Today million's of people are making a handsome income every month. There are many webmasters (people who run their websites) who are earning more than $50,000 every month without any effort. Well this sounds Fishy, but its true$50,000 every month without any effort. Well this s Email : info@indiagoogleworld.com Phone no : 9052559825 Area : India Location : Hyderabad y, but its true URL: http://www.indiagoogleworld.com/Adsense.htm
 
From author Mark Alexander Smith in category General Web Marketing>Search Engine Optimization
Search Engine Optimization for Dummies
Search Engine Optimization sounds difficult to most. One reason being that search engines are very technical things and the other being that the word optimization has five syllables. But in truth Search Engine Optimization is not an exact science, even though the companies that advertise this service will make it out to be. The steps that are outlined in this article will help you to optimize your site correctly at the design stage of your website.
 
From author Rachel Ray in category Internet>Providers
Outsourcing Staff: Benefits of Remote staff, Offshore and Online staff
This rise in the need for outsourcing staff caused numerous Business Process Outsourcing or BPO companies to mushroom in different parts of the world, more specifically in developing countries such as China, India and the Philippines. Why developing countries? Developing countries have a rich labor resource for price that’s almost 70% cheaper compared to hiring local office staff!
 
From author David Domingues in category Programming Languages>PHP
How to create a simple Database Access Layer (DBAL)
Defining all accesses to a MYSQL database on a dynamic page can be painful when you have a lot of information fields to manage. This small class is the beginning for a database layer abstraction (DBAL). Using it, you will never have to make a query again, deal with its syntax, know where to put quotes and not, know what the primary keys of the tables are, etc.... In fact, this information already exists in a database called information_schema. If performance of a site is not the main issue and you want it to make your site maintainable before all, then using this information to simplify the life of the programmer can be the key. But know that these kind of things, and by extension every DBAL, Object Relational Mapper (ORM), like Doctrine for instance, or frameworks like Cake or Zend have huge costs in terms of performance, but will ease your job. It's only a question of choice...
 
From author Matthew Parker in category Software>Training
SAP Training & Courses - What Can It Do For Your Career
Well before reflecting upon that query lets have a quick recap of what we are talking about. When we verbalize about SAP, we are verbalizing about a world industry leader in ERP (Enterprise Resource Planning) software. In fact SAP is the third biggest software enterprise of the globe, with over12000 enterprises using SAP, having round 80,000 installations and over 12,000,000 individuals making use of it. Hence rest assured whatever you are planning to do with SAP, you are managing with something serious and verified over the yrs.
 
From author Rachel Ray in category General discussion>Human resources
Outsourcing Virtual Assistant Jobs: You've got a Choice from Recruitment Service Companies
You can easily take your pick from the various outsourcing jobs like a virtual assistant that are now needed by many businesses. They can hire you on a short or long term basis depending upon the project requirements from recruitment services and recruitment companies. All you need to have is a small home office with a computer unit with a broad band or DSL connection and you can start your foray your chosen career path.
 
From author Rachel Ray in category General discussion>Human resources
Call Centre, Contact Centre, Telemarketers, Telemarketing Staff, Customer Service & CSR Career Guide
If you are considering this BPO service or just being a call centre or contact centre agent, Telemarketer/s and Telemarketing staff, customer service rep or CSR interest you, then this is the right time to read this.
 
From author David Domingues in category Programming Languages>Ajax
Simple Ajax Tutorial - Updating part of your form without reloading all
If you are thinking about turning your webpage into a desktop application, you should think about Ajax programming. Ajax will make your site more user-friendly, avoiding the full refresh each retrieval of data requires when calling server functions
 
From author David Domingues in category Programming Languages>CakePHP
Multi-language country combobox
Helper to instantly build a combobox with countries in 6 different languages based on XML data retrieval.
 
From author David Domingues in category Programming Languages>PHP
How to divide query results into various pages. The navigation paginator class in PHP
When you retrieve a large amount of rows from a database consultation, you might want to display your result in several pages instead of having everything listed on a very long page. The paginator component might help the programmer to minimize the impact of transforming a simple data display into a complex multipage management display.
 
From author David Domingues in category Programming Languages>PHP
How to create a complete set of thumbnail images, based on a folder path, and display the created content in PHP
If you have a folder with images and want to show those images on your website, you will probably think about showing thumbnails of each of them. This way you will be able to better organize your content and minimize the download time on the page by considerably reducing the size of the images. Additionaly, the user will be able to see the full size image by clicking on the thumbnail picture.
 
From author Get Google Ads For Free Scam Review Blog in category General Web Marketing>Pay per click advertising
Google AdWords Ads Now Free? Are You Kidding me?
Welcome to the Get Google Ads For Free Scam Review Article. This is the Google AdWords Ads Now Free Article. A new breakthrough secret is all you now need in order to get your Google AdWords pay-per-clicks FREE
 
From author Gugu Maseko in category General Web Marketing>Ecommerce
Guidelines to Free Internet Advertising and Website Promotion
Advertising online can bring more traffic then paid advertising, classified ads being more popular. Most of free classified ads web sites give you the power to facilitate marketing with features such as classified ads submitter forms.
 
From author Chris Channing in category General Web Marketing>Web hosting
Why Premium Web Hosting Is Better For Your Website
There are numerous web hosting companies on the internet, including both free and premium accounts. A lot of people choose a free account because they cannot afford a premium, or don't want to shell out the cash. Premium accounts are always the better option, and with packages available in all shapes and sizes, you can definitely get your money's worth.
 
Articles
DHTML
Falling image from the to...
Dynamise image behaviour ...
PHP
How to build a dynamic se...
How to divide query resul...
How to create a complete ...
How to create a simple Da...

Top Rated
How to make a dynamic for... 5/5 (C# development)
Call Centre, Contact Cent... 5/5 (Human resources)
What To Expect From Dell ... 5/5 (General considerations)
Nofollow 101 - Understand... 5/5 (Search Engine Optimization)
How to divide query resul... 5/5 (PHP)
Cool Tools and Firefox Ex... 5/5 (Search Engine Optimization)


Sponsors
 
Free Downloads from download.com
 
Free Downloads from FreewareFiles
 
Free Downloads from SnapFiles.com
 
FilesLand.com
 
Free Downloads from Tucows
 
Russian site about Portugal