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 GD Library file compression function

  • 03-06-2007 03:57PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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