Jump to content

GD2 function fading images....


dsartain

Recommended Posts

I've got a function that I'm using to make thumbnails out of images....but the problem is that it's fading the images....I can't figure out why though....please help!!

 


// actual function
function thumbnail($image_path,$thumb_path,$image_name,$thumb_width) 
{ 
    $src_img = imagecreatefromjpeg("$image_path/$image_name"); 
    $origw=imagesx($src_img); 
    $origh=imagesy($src_img); 

$new_w = $thumb_width;		
$new_h=($origh*($new_w))/$origw; //added to get better proportions
     
    $diff=$origw/$new_w; 
    //$new_h=$new_w; //removed to get better proportions
    $dst_img = imagecreate($new_w,$new_h); 
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); 

    imagejpeg($dst_img, "$thumb_path/$image_name"); 
    return true; 
} 


//usage
thumbnail("/var/www/html/dsartain/images/gallery/", "/var/www/html/dsartain/images/gallery/thumbnails/", $userfile_l_name, 150) ;

Link to comment
https://forums.phpfreaks.com/topic/38585-gd2-function-fading-images/
Share on other sites

Go to http://www.the24hourshow.net/dsartain/gallery.php

 

The two images with "Blue Wall" Captions and the one with "Swimming Lessons"...all are towards the bottom...images as colors should appear are on that page also (though I didn't use GD2 for those...)

function thumbnail($image_path,$thumb_path,$image_name,$thumb_width) 
{ 
    $src_img = imagecreatefromjpeg("$image_path/$image_name"); 
    $origw=imagesx($src_img); 
    $origh=imagesy($src_img); 

$new_w = $thumb_width;		
$new_h=($origh*($new_w))/$origw; //added to get better proportions
     
    $diff=$origw/$new_w; 
    //$new_h=$new_w; //removed to get better proportions
    $dst_img = imagecreate($new_w,$new_h); 
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); 

//just added 100 for $quality...no change in display though
    imagejpeg($dst_img, "$thumb_path/$image_name", 100); 
    return true; 
} 

whoops!!!

 

I forgot one minor thing....

 

function thumbnail($image_path,$thumb_path,$image_name,$thumb_width) 
{ 
    $src_img = imagecreatefromjpeg("$image_path/$image_name"); 
    $origw=imagesx($src_img); 
    $origh=imagesy($src_img); 

$new_w = $thumb_width;		
$new_h=($origh*($new_w))/$origw; //added to get better proportions
     
    $diff=$origw/$new_w; 

    $dst_img = imagecreatetruecolor($new_w,$new_h); //I left this line out...doh!!
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); 
    imagejpeg($dst_img, "$thumb_path/$image_name", 100); 
    return true; 
} 

 

Thanks a lot for the help!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.