Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Design
php image resize
Bananna man
Hi,
I have been trying to get a GD library image resize and file resize script going for a few days now but with little success. The scripts ive been trying to incorporate are a bit over my head, they all check file extension and have different rules for the different extensions but i just need to to run for .jpg's.
I can either resize the image when saving it in my site directory or resize them on the fly so if anyone knows a simple script for doing this please let me know. Everything ive seen so far is using about 4 or 5 functions and because its my first time using any of them im in over my head before i even get half way though the script so when something doent work i dont even know where to start looking.
Thanks
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
seamus
Here is an *extremely* simple resize function I wrote a few years back. I haven't rewritten it because it serves the purpose that I wrote it for - I'm not accepting input from the public or otherwise concerned about getting it perfect.
[php]function resizeAndCopy($filename, $newfilename, $new_width, $new_height) {
//Creates a resized image from $filename and copies the image to $newfilename
list($width, $height) = getimagesize($filename);
//Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if(imagejpeg($image_p, $newfilename, 100)) return true;
else return false;
}[/php]
What this does in the script is take an uploaded photo, then creates a resized copy in a "thumbs" directory.
Bananna man
Thanks Seamus,
I'm just trying it out now and it seems to be doing what i need.