Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

php image resize

  • 18-08-2007 11:00am
    #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,317 ✭✭✭✭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