Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize an existing image on my server

Status
Not open for further replies.

markhkram

IS-IT--Management
Dec 30, 2008
32
US
I have a bunch of images on my server that I'd like to write a php file that will grab the existing file in a directory, and scale it down to thumbnail size, and place the new file in the same directory under a different name.

So basically make the existing /folder/1.jpg (which is 640x480) into /folder/1small.jpg (which I need to have thumbnail sized). And still retain both files...

Thanks!
 
Have you looked at the imagecopyresized() function?


Example is there if you scroll down.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
I tried that, but couldn't get it to work on already existing images... :S
 
Could you tell us what if any errors you received?

Why id didn't work for you?

Some more info n your part can help us help you.

BTW if you don't need the image displayed onto the screen, you can remove the header part.

This should work:
Code:
<?php
// File and new size
$filename = 'images/portal.jpg';
$newfilename="images/pthumb.jpg";
$percent = 0.2;


// Content type


// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);

$source = imagecreatefromjpeg($filename);

// Resize
$res=imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb,$newfilename);


?>



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top