Important alert: (current site time 7/15/2013 10:31:28 AM EDT)
 

VB icon

A simple thumbnail generator (with correct aspect ratio)

Email
Submitted on: 7/15/2001 3:56:25 AM
By: Digital  
Level: Intermediate
User Rating: By 8 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 25617
author picture
(About the author)
 
     Resizes an image in the browser without throwing off the aspect ratio... basically it makes the image appear smaller, but not stretch the height... also: you dont need to know how wide/high the image is before, just how wide you want it. Someone called into question my reasoning for even using this function, if you can define this information statically in the html, but what the rude person doesnt realize is that if you are displaying hundreds of images in a while or for loop, you need to be able to define this dynamically. So to the responder: _You_ do your research first. --- Please keep in mind, this is not intended for large files, as it is intended for small files of different dimensions. It is meant for uniformed look, not efficient loading.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :A simple thumbnail generator (with correct aspect ratio)
//**************************************
Function written by Digital, of the DE-Network. Please cite Digital with the URL http://www.de-net.org in your credits, and with the source.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: A simple thumbnail generator (with correct aspect ratio)
// Description:Resizes an image in the browser without throwing off the aspect ratio... basically it makes the image appear smaller, but not stretch the height... also: you dont need to know how wide/high the image is before, just how wide you want it. Someone called into question my reasoning for even using this function, if you can define this information statically in the html, but what the rude person doesnt realize is that if you are displaying hundreds of images in a while or for loop, you need to be able to define this dynamically. So to the responder: _You_ do your research first. --- Please keep in mind, this is not intended for large files, as it is intended for small files of different dimensions. It is meant for uniformed look, not efficient loading.
// By: Digital
//
// Inputs:$image_file is the path to the image, relative to the script, $size is the max width.
//
// Side Effects:Internal bleeding, constipation during diahrea, blindness, shortness of breath... but thats all.. oh wait: death.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=376&lngWId=8//for details.//**************************************

function OutputThumbnail($image_file, $size)
{
	if (file_exists($image_file))
	{
		$size = GetImageSize($image_file);
		$wid = $size[0] - abs($size - $size[0]);
		$hie = $size[1] - abs($size - $size[0]);
		?>
		<img width="<? echo $wid; ?>" height="<? echo $hie; ?>" src="<? echo $image_file; ?>">
		<?
	}
}


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/22/2003 11:47:11 AM

This code didn't work for me, so I editted it and came up with: function OutputThumbnail($image_file, $size) //sets the size of image { if (file_exists($image_file)) { $size1 = GetImageSize($image_file); $hie = $size1[1]; $wid = $size1[0]; if($hie>$size) { $multiplier=$size/$hie; $wid = $wid*$multiplier; $hie = $hie*$multiplier; } echo "
< a href=\"$image_file\" target=\"_blank\">< img width=\"$wid\" height=\"$hie\" src=\"$image_file\" border=\"0\">
"; } } -Cassova
(If this comment was disrespectful, please report it.)

 
2/9/2004 11:18:12 PMt0rus

this code is useless in php, fot the same effect you may use javascript, which works almost on all servers, use php to generate acual thumbnails, not just resize and display 5MB pictures
(If this comment was disrespectful, please report it.)

 
7/11/2005 9:01:27 PMHackMan Curda

it is bad where open the string of php and where you close it ?
(If this comment was disrespectful, please report it.)

 
6/28/2006 4:58:32 AMhacker20id

I thought it uses gd functions...

it is better to use html... hehe
(If this comment was disrespectful, please report it.)

 
4/14/2010 7:50:40 PMCurda

this code is to prety ugly imagine if the image is a blob in mysql array or list, this function make error

make a better one but good for u for uploading a thing...
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.