Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts

    Change image filesize and sizes, gd

    How can I change the filesize and sizes of an image which will be created off an uploaded file? Basically trying to create thumbnails which won't take a long time to load and use up so much bandwidth. No idea if this is the right way to give you info of my gd or not http://www.phathosting.co.uk/gd.php

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I used to have a script like that but I believe it was in Perl and I can't find it anymore.

    I think you should do it like this:

    Create a GD-image from the uploaded file
    something like this: GD->createNewImageFromFile("uploaded.jpg")
    create another (blank) GD-image

    check the size of the image like this:
    oldW = orgImageW;
    oldH = orgImageH;
    maxW = 200;
    maxH = 150;

    if(oldW>maxW) {
    tempVar = oldW/maxW;
    newW = oldW/tempVar;
    newH = oldH/tempVar;
    }
    if(oldH>maxH) {
    tempVar = oldH/maxH;
    newW = oldW/tempVar;
    newH = oldH/tempVar;
    }
    use the CopyResized-option or something to copy the uploaded image to the blank one (resized)

    I hope this helps you (a little)

    Laetherzz, Chris
    My Website
    010100010011110101110100011011110111000001101000

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To get the compression to assure a certain filesize you would need to recurse
    imagejpeg($img_ref,'path/name.jpg',$compression)
    , then read filesize('path/name.jpg') and keep reassigning $compression until you meet the filesize limitations.

    Eg - start at maybe 85 quality - save, filesize test - then determine if the file is too big or small - resave if needed
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Ta, I'll see what I come up with


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •