Important alert: (current site time 5/24/2013 4:55:02 AM EDT)
 

VB icon

Image resize without distortion and keeping proportions

Email
Submitted on: 4/27/2012 5:23:09 PM
By: Amit Kumar Gaur  
Level: Advanced
User Rating: Unrated
Compatibility: PHP 5.0
Views: 1321
author picture
(About the author)
 
     Image resize without distortion and keeping proportions. Image distortion is the normal problem with the image resize in any programming language. You need to have good knowledge of math to resizing the image. I have implemented image resize code without distortion in PHP. You can easily convert it in the any other programming language for ex: ASP.Net, JSP etc:
 
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: Image resize without distortion and keeping proportions
// Description:Image resize without distortion and keeping proportions.
Image distortion is the normal problem with the image resize in
any programming language. You need to have good knowledge of math to
resizing the image.
I have implemented image resize code without distortion in PHP.
You can easily convert it in the any other programming language
for ex: ASP.Net, JSP etc:
// By: Amit Kumar Gaur
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=3012&lngWId=8//for details.//**************************************

Here is the listed below code:
====================================
img_resize.php
$filename = "http://3.bp.blogspot.com/-SYlfCqayWE4/TnmVU3cFOzI/AAAAAAAAAD4/CNAeVYvluO8/s1600/auto-resume-broken-uploader.jpg";
$nw = 170; // new width
$nh = 128; // new height
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($filename);
if($width<= $nw) {
$nw=$width;
}
$newHeight = $height*$nw/$width; // calculate new height here
if($newHeight > $nh) {
$nw = $width*$nh/$height;
$newHeight=$nh;
}
$image_s = imagecreatetruecolor($nw,$newHeight);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_s, $image, 0, 0, 0, 0, $nw,$newHeight,$width,$height);
imagejpeg($image_p, null, 100);
use it as listed below:
<img src="img_resize.php" />
Note that you can also make the parameter for height and width.
Find full code here also:
http://amitkgaur.blogspot.in/2012/03/image-resize-without-distortion-and.html


Other 30 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 Advanced 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

 There are no comments on this submission.
 

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.