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

php GD Library file compression function

Options
  • 03-06-2007 3:57pm
    #1
    Registered Users Posts: 673 ✭✭✭


    Hi,

    Im using the GD library extension for the first time as i need to show thumbnail images from my database. Is their a GD Library function that will allow me to compress an image before it is output to the browser? I cant seem to find a function for this but im sure its possible?

    Thanks


Comments

  • Closed Accounts Posts: 270 ✭✭CoNfOuNd


    I'm not completely sure but is this what you need..

    http://www.weberdev.com/get_example-4594.html


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Cheers, ill give that a lash. I'm surprised that their doesn't seem to be a GD Library function for this.


  • Registered Users Posts: 1,221 ✭✭✭thekooman


    hi,
    i ain't a developer but i use "Bugzilla" to log bugs. some of the perl modules used compress images from bmp to gif and use GD libraries and also something called "image::magick".

    i don't have an exact list but if you have a look through the bugzilla section in Google groups it might help.


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    Jpegs ... are normally compressed images ? ... and you normally don't output bmps to browsers ...

    Are you just looking for

    bool imagejpeg ( resource $image [, string $filename [, int $quality]] )

    Change the Quality to suit ?


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    forbairt wrote:
    Jpegs ... are normally compressed images ? ... and you normally don't output bmps to browsers ...

    Are you just looking for

    bool imagejpeg ( resource $image [, string $filename [, int $quality]] )

    Change the Quality to suit ?

    That's what I was thinking....the link above is a file resizer/thumbnail generator......

    The imagejpeg function will compress an image, but it'll affect the quality.

    The only other "compression" I can think might be required is if the OP is delivering high-res images and wants to generate a TAR/ZIP file from them to make them smaller without losing quality ?


  • Advertisement
  • Registered Users Posts: 3,594 ✭✭✭forbairt


    I would have assumed the saving would have been minimal ...


    maybe they are just after a resize ... ??
    <?php
    // File and new size
    $filename = 'test.jpg';
    $percent = 0.5;
    
    // Content type
    header('Content-type: image/jpeg');
    
    // Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;
    
    // Load
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);
    
    // Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    
    // Output
    imagejpeg($thumb);
    ?> 
    


Advertisement