PHP Classes
elePHPant
Icontem

Thumb-nailit: Generate size limited thumbnails of a given image

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2005-06-27 (10 years ago) RSS 2.0 feedStarStarStarStar 72%Total: 1,541 All time: 2,413 This week: 1,303Up
Version License Categories  
thumb-nailit 1.0GNU General Publi...Graphics
Description Author  

This is a simple class that can generate a thumbnail graphic of a given image.

The class generates a thumbnail graphic that keeps the proportion of original image and at the same time neither the width nor the height do not exceed a given size.

The class reads the original image using a given file name. It detects the image type checking the file name extension. It supports either GIF, JPEG and PNG formats.

The thumbnail image is stored in another file given its file name. The output image format is also determined from the output file name extension. The supported output formats are the same.

Picture of Drazen
Name: Drazen <contact>
Classes: 1 package by
Country: Croatia Croatia
Age: ???
All time rank: 16913 in Croatia Croatia
Week rank: 1504 Up2 in Croatia Croatia Up

Details provided by the author  
                   THUMBNAIL CREATION CLASS

PURPOSE:

This class solves two rather common needs 

1 Keeping the uploaded images within a certain reasonable size. 
	I had many clients who have upload facility where they upload images directly from their camera.
	Who needs an image that is 2100 x 1500 pixels in size?
	You can use this class to filter all uploads and cut the images to certain size.
	
2 Creating thumbnails for image/images.
	All over the web you can see "click to view larger image".
	This class creates those small images quickly and easily.

In short - this class reduces image size and thus file size as well.



ADVANTAGE:

All classes so far made you specify BOTH thumbnail dimensions (width and height).
In a typical situation, though, that is a problem.

In all galleries, CMS-es, shopping carts etc, you don't know both dimensions because various
images will have different proportions.


What you want is to simply keep the image within a certain width OR height. 
You don't want to specify BOTH width and height because that would distort 
all images that do not have the same proportions.

That is where this class comes in.
Just enter the "higher pixel value" and it will calculate the other value and resize the image proportionally.


I needed such function in several applications. There was no class that does it so I made it.



If you are not sure what "higher pixel value" is have a look:

	
    lesser pixel value

	---------	
	|	|
	|	|
	|	|	higher pixel value
	|	|
	|	|
	|	|
	|	|
	---------




	    higher pixel value
	-------------------------
	|			|
	|			|
	|			|	lesser pixel value
	|			|
	-------------------------



TECH DETAILS:

This class relies on GD PHP extension.
You can test if your server has it with a simple PHP script:

<?
phpinfo()
?>


If the GD extesion is present, it will be listed (can be a long scroll though).
When you are specifying the image to be thumbnailed and the name for the image 
to be saved as, remember to use a proper file path.

If you are not sure about that, you can use a following script.

<?

if($HTTP_SERVER_VARS){
  foreach($HTTP_SERVER_VARS as $Key=>$Value)
  {
    $$Key = $Value;

print "$$Key -- $Value<br>";
  }
}


?>


Values such as

$DOCUMENT_ROOT
$SCRIPT_FILENAME
$PATH_TRANSLATED

will show you what folders/directories your files reside in.

  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example
Accessible without login Plain text file example_with_explanations.php Example Example with explanations
Accessible without login Plain text file readme.txt Doc. Readme (Documentation)
Plain text file thumb-nailit.php Class Class

 Version Control Unique User Downloads Download Rankings  
 0%Total:1,541All time:2,413
 This week:0This week:1,303Up
 User Ratings  
 
 All time
Utility:95%StarStarStarStarStar
Consistency:80%StarStarStarStarStar
Documentation:80%StarStarStarStarStar
Examples:90%StarStarStarStarStar
Tests:-
Videos:-
Overall:72%StarStarStarStar
Rank:134