| | |
How to resize images
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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 . •
•
Join Date: Apr 2009
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
Can any one help me how toresize imagesin 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 itsquality.
Please check blow Pices of Code
PHP Syntax (Toggle Plain Text)
$tmpFName = $_FILES["UploadFloorPlane"]["tmp_name"]; $fType = $_FILES["UploadFloorPlane"]["type"]; $fSize = $_FILES["UploadFloorPlane"]["size"]; list($width, $height, $type, $attr) = getimagesize($tmpFName); if($width > 0) { $fType = image_type_to_mime_type($type); $img_valid = "true"; } else $img_valid = "false"; if($img_valid == "true"){ if(($fType == 'image/jpeg') || ($fType == 'image/pjpeg')){ $pExt = ".jpg"; } elseif($fType == 'image/gif'){ $pExt=".gif"; } elseif($fType == 'image/png'){ $pExt=".png"; } else{ $result = -2; } $rand=rand(0,10000); $Enlarge = "ImageName"; $thumb = "ImageName_thumb"; $origImage = $Enlarge ; copy($tmpFName,$origImage.$pExt); chmod ($origImage.$pExt, 0755); // octal; correct value of mode $NormalThumbImgName = $Enlarge.$pExt; $SmallThumbImgName = $thumb.$pExt; $DestPath = getcwd(); $objThumbnail = new ThumbNail(); $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.
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..
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..
•
•
Join Date: Apr 2009
Posts: 5
Reputation:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
$tmpFName = $_FILES["UploadFloorPlane"]["tmp_name"]; $fType = $_FILES["UploadFloorPlane"]["type"]; $fSize = $_FILES["UploadFloorPlane"]["size"]; list($width, $height, $type, $attr) = getimagesize($tmpFName); if($width > 0) { $fType = image_type_to_mime_type($type); $img_valid = "true"; } else $img_valid = "false"; if($img_valid == "true"){ if(($fType == 'image/jpeg') || ($fType == 'image/pjpeg')){ $pExt = ".jpg"; } elseif($fType == 'image/gif'){ $pExt=".gif"; } elseif($fType == 'image/png'){ $pExt=".png"; } else{ $result = -2; } $rand=rand(0,10000); $Enlarge = "ImageName"; $thumb = "ImageName_thumb"; $origImage = $Enlarge ; copy($tmpFName,$origImage.$pExt); chmod ($origImage.$pExt, 0755); // octal; correct value of mode $NormalThumbImgName = $Enlarge.$pExt; $SmallThumbImgName = $thumb.$pExt; $DestPath = getcwd(); $objThumbnail = new ThumbNail(); $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.
Hi, I have made a function that will resize images and is as follows:
Hope that helps ya as I would imagine that some of the previous posts would be a little confusing without the syntax highlighter.
php Syntax (Toggle Plain Text)
<?php function resize_image($filename,$newwidth,$newheight) { if (!file_exists($filename) || !in_array(preg_replace('/(.*)[.]([^.]+)/is','$2',basename($filename)),array('png','jpg','jpeg','gif','xbm','xpm','wbmp'))) { //note .wbmp is 'wireless bitmap' and not 'windows bitmap'. return false; } else { $ext=preg_replace('/(.*)[.]([^.]+)/is','$2',basename($filename)); if ($ext=='jpg') { $ext='jpeg'; } $ext='imagecreatefrom'.$ext; list($width, $height) = getimagesize($filename); $thumb = imagecreatetruecolor($newwidth, $newheight); $source = $ext($filename); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); return $thumb; } } $img = resize_image('file_from.gif','320','280'); //save image to file imagejpeg ($img,'file.gif',100); ?>
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
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
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
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..
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.
•
•
•
•
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]
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.
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.
![]() |
Similar Threads
- Generate Thumbnail images on the fly. (PHP)
- How to resize images at runtime using mouse... (VB.NET)
- Is there a standard for handling missing images' space? (Site Layout and Usability)
- Upload and Resize PNG and GIF images (PHP)
- How to bulk resize JPG files in folder and subfolder (Shell Scripting)
- Problem with uploading images to website (PHP)
- Indexing Images (PHP)
- Uploading entire directories of images using PHP (PHP)
- Reducing pixelization in images (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: Retrieving changing remote content?
- Next Thread: Picture Labeler using PHP/MySQL
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube






