Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

php image resize

  • 18-08-2007 12:00PM
    #1
    Registered Users, Registered Users 2 Posts: 673 ✭✭✭


    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


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭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.


  • Registered Users, Registered Users 2 Posts: 673 ✭✭✭Bananna man


    Thanks Seamus,

    I'm just trying it out now and it seems to be doing what i need.


Advertisement