How to resize images

Reply

Join Date: Mar 2009
Posts: 28
Reputation: nathenastle is an unknown quantity at this point 
Solved Threads: 2
nathenastle's Avatar
nathenastle nathenastle is offline Offline
Light Poster

How to resize images

 
0
  #1
Apr 21st, 2009
Can any one help me how to resize images in php with out changing its original quality,that is if an image with size 100/100 when it reduced to 40/30 or any our required dimensions with out changing its quality .
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 254
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: How to resize images

 
0
  #2
Apr 21st, 2009
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 5
Reputation: BaburajSNS is an unknown quantity at this point 
Solved Threads: 0
BaburajSNS BaburajSNS is offline Offline
Newbie Poster

Re: How to resize images

 
0
  #3
Apr 21st, 2009
Originally Posted by nathenastle View Post
Can any one help me how to resize images in php with out changing its original quality,that is if an image with size 100/100 when it reduced to 40/30 or any our required dimensions with out changing its quality .

Please check blow Pices of Code
  1. $tmpFName = $_FILES["UploadFloorPlane"]["tmp_name"];
  2. $fType = $_FILES["UploadFloorPlane"]["type"];
  3. $fSize = $_FILES["UploadFloorPlane"]["size"];
  4. list($width, $height, $type, $attr) = getimagesize($tmpFName);
  5. if($width > 0) {
  6. $fType = image_type_to_mime_type($type);
  7. $img_valid = "true";
  8. } else
  9. $img_valid = "false";
  10.  
  11. if($img_valid == "true"){
  12. if(($fType == 'image/jpeg') || ($fType == 'image/pjpeg')){
  13. $pExt = ".jpg";
  14. }
  15. elseif($fType == 'image/gif'){
  16. $pExt=".gif";
  17. }
  18. elseif($fType == 'image/png'){
  19. $pExt=".png";
  20. }
  21. else{
  22. $result = -2;
  23. }
  24. $rand=rand(0,10000);
  25. $Enlarge = "ImageName";
  26. $thumb = "ImageName_thumb";
  27. $origImage = $Enlarge ;
  28. copy($tmpFName,$origImage.$pExt);
  29. chmod ($origImage.$pExt, 0755); // octal; correct value of mode
  30. $NormalThumbImgName = $Enlarge.$pExt;
  31. $SmallThumbImgName = $thumb.$pExt;
  32. $DestPath = getcwd();
  33. $objThumbnail = new ThumbNail();
  34. $objThumbnail->CreateThumb($SmallThumbImgName,$DestPath.$origImage.$pExt,$DestPath,40,30,false,false);


Download the below Url Class files
http://www.phpclasses.org/browse/file/4883.html


BaburajSns
Securenext Softwares Pvt
Last edited by Ezzaral; Apr 21st, 2009 at 1:13 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: How to resize images

 
0
  #4
Apr 21st, 2009
One more point...
By using our php codes..
Changing from 100X100 image to 40X50 image will result into same quality image...But vice versa will give corrupted image..

So make it note when your are going develop in your projects..
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 28
Reputation: nathenastle is an unknown quantity at this point 
Solved Threads: 2
nathenastle's Avatar
nathenastle nathenastle is offline Offline
Light Poster
 
0
  #5
Apr 21st, 2009
Thanks for your replay but where is the code iasked can you please tell me
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 5
Reputation: BaburajSNS is an unknown quantity at this point 
Solved Threads: 0
BaburajSNS BaburajSNS is offline Offline
Newbie Poster

Re: How to resize images

 
0
  #6
Apr 21st, 2009
  1. $tmpFName = $_FILES["UploadFloorPlane"]["tmp_name"];
  2. $fType = $_FILES["UploadFloorPlane"]["type"];
  3. $fSize = $_FILES["UploadFloorPlane"]["size"];
  4. list($width, $height, $type, $attr) = getimagesize($tmpFName);
  5. if($width > 0) {
  6. $fType = image_type_to_mime_type($type);
  7. $img_valid = "true";
  8. } else
  9. $img_valid = "false";
  10.  
  11. if($img_valid == "true"){
  12. if(($fType == 'image/jpeg') || ($fType == 'image/pjpeg')){
  13. $pExt = ".jpg";
  14. }
  15. elseif($fType == 'image/gif'){
  16. $pExt=".gif";
  17. }
  18. elseif($fType == 'image/png'){
  19. $pExt=".png";
  20. }
  21. else{
  22. $result = -2;
  23. }
  24. $rand=rand(0,10000);
  25. $Enlarge = "ImageName";
  26. $thumb = "ImageName_thumb";
  27. $origImage = $Enlarge ;
  28. copy($tmpFName,$origImage.$pExt);
  29. chmod ($origImage.$pExt, 0755); // octal; correct value of mode
  30. $NormalThumbImgName = $Enlarge.$pExt;
  31. $SmallThumbImgName = $thumb.$pExt;
  32. $DestPath = getcwd();
  33. $objThumbnail = new ThumbNail();
  34. $objThumbnail->CreateThumb($SmallThumbImgName,$DestPath.$origImage.$pExt,$DestPath,40,30,false,false);


Download the CreateThumb Class files function
http://www.daniweb.com/forums/post85...tml#post850887
Last edited by Ezzaral; Apr 21st, 2009 at 1:15 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,449
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: How to resize images

 
0
  #7
Apr 22nd, 2009
Hi, I have made a function that will resize images and is as follows:
  1. <?php
  2. function resize_image($filename,$newwidth,$newheight) {
  3. if (!file_exists($filename) || !in_array(preg_replace('/(.*)[.]([^.]+)/is','$2',basename($filename)),array('png','jpg','jpeg','gif','xbm','xpm','wbmp'))) {
  4. //note .wbmp is 'wireless bitmap' and not 'windows bitmap'.
  5. return false;
  6. } else {
  7. $ext=preg_replace('/(.*)[.]([^.]+)/is','$2',basename($filename));
  8. if ($ext=='jpg') { $ext='jpeg'; }
  9. $ext='imagecreatefrom'.$ext;
  10. list($width, $height) = getimagesize($filename);
  11. $thumb = imagecreatetruecolor($newwidth, $newheight);
  12. $source = $ext($filename);
  13. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  14. return $thumb;
  15. }
  16. }
  17. $img = resize_image('file_from.gif','320','280');
  18. //save image to file
  19. imagejpeg ($img,'file.gif',100);
  20. ?>
Hope that helps ya as I would imagine that some of the previous posts would be a little confusing without the syntax highlighter.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 1
Reputation: adnan3250 is an unknown quantity at this point 
Solved Threads: 0
adnan3250 adnan3250 is offline Offline
Newbie Poster

Re: How to resize images

 
0
  #8
Jun 5th, 2009
I do not understand why we (the programmers) use unnecessary huge buggy codes of our own for resizing images??!! As we've phpThumb, custom image resizing functions are just a history. Then why do we manually write those codes again and make our script buggy!

Yes I know what I am saying. I was using my own codes for image resizing and one day I got problem with corrupted images and got no solution. Then I used phpThumb and the problem is fixed..
Last edited by Ezzaral; Jun 5th, 2009 at 6:32 pm. Reason: Snipped blog plug. Keep it on site please.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: How to resize images

 
0
  #9
Jun 5th, 2009
Originally Posted by adnan3250 View Post
I do not understand why we (the programmers) use unnecessary huge buggy codes of our own for resizing images??!! As we've phpThumb, custom image resizing functions are just a history. Then why do we manually write those codes again and make our script buggy!

Yes I know what I am saying. I was using my own codes for image resizing and one day I got problem with corrupted images and got no solution. Then I used phpThumb and the problem is fixed..

To know more details please visit this [URL snipped]
Because that's how programmers work. phpThumb didn't magically appear, there was some dumb guy/gal saying "Well I don't like that library, I'm going to write my own and name it phpThumb." It just so happens other people started using it. So, of course, there are still programmers that say "Well, I don't like that library I'm going to write my own."

Most of the time it's because in programmers' heads their code rocks and everyone else's sucks.
Last edited by Ezzaral; Jun 5th, 2009 at 6:34 pm. Reason: Snipped blog url from quoted text.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC