Pixelpost

Authentic Photoblog Flavour


Go Back   Pixelpost Forum > DEVELOPMENT > Hacks and Modifications

Post Reply
 
Thread Tools
  #1  
Old 10-08-2005, 05:56 PM
brian connolly Offline
pp veteran
 
Join Date: Aug 2005
Posts: 59
hard code compresson level on resize?

Can some one advise me please? I'd like to hard code a compression level for a resize script using gd 201. Presently, a 1,800 kb file is typically reduced to 100 kb. Obviously, we're loosing a lot of detail.

Where? How? Thanks in advance.

Code:
function resizeimage($args) {
    $file = $args['file'];
    $max_width = $args['max_width'];
    $max_height = $args['max_height'];
    define(IMAGE_BASE, "../images");
    $image_path = IMAGE_BASE . "/$file";
    $img = null;
    $ext = strtolower(end(explode('.', $image_path)));
 
    if ($ext == 'jpg' || $ext == 'jpeg') {
      $img = @imagecreatefromjpeg($image_path);
        } else if ($ext == 'png') {
        $img = @imagecreatefrompng($image_path);
        } else if ($ext == 'gif') {
        $img = @imagecreatefromgif($image_path);
        }
        
        exec("cp " . $image_path . " " . $image_path . "_orig");
        echo "$image_path";     
         
    if($img) {
        $width = imagesx($img);
        $height = imagesy($img);
        $scale = min($max_width/$width, $max_height/$height);
        if($scale < 1) {
            $new_width = floor($scale*$width);
            $new_height = floor($scale*$height);
            $tmp_img = imagecreatetruecolor($new_width,$new_height);
            if(function_exists(imagecopyresampled)) {
                imagecopyresampled($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
                } else {
                imagecopyresized($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
                }
            imagedestroy($img);
            $img = $tmp_img;
            }
        }
Reply With Quote
  #2  
Old 10-08-2005, 06:18 PM
Joe[y]'s Avatar
Joe[y]+ Offline
Team Pixelpost
 
Join Date: Mar 2005
Location: UK
Posts: 3,101
Send a message via MSN to Joe[y]
are you talking about resize of thumbnails? because you can change the compression level in the admin panel for that.
Reply With Quote
  #3  
Old 10-08-2005, 06:34 PM
brian connolly Offline
pp veteran
 
Join Date: Aug 2005
Posts: 59
Nope. Well, almost.

The above code is utok's hack/mod to resize and make wallpapers. It is a rework of the thumbnail code.

That said, I just cannot tell if it is also utilizing the thumbnails compression ratio. And if it is, where? Or, might there be default limitations set by my hosting company?

Thoughts?
Reply With Quote
  #4  
Old 10-08-2005, 09:21 PM
brian connolly Offline
pp veteran
 
Join Date: Aug 2005
Posts: 59
imagejpeg($img, "../images/$file",100);
Reply With Quote
Post Reply


Thread Tools




All times are GMT. The time now is 07:32 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. | Style Design: d3 designs