Jump to content

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!!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.