Jump to content

Recommended Posts

Hi can anyone tell me how i can apply an overlay to following thumbnail creation code, i want to overlay a white image with adjustable transparency, basically make the thumbnails faded;

 

function file_thumb($file,$album,$file_name) {
    global $thumb_width,$thumb_height,$jpg_quality;

    //Get the file extension!

    $file_ext=file_ext($file);

    //The GD Libary only supports jpg and gif really, well it can only make a gif a jpg. There are other ways like image magik, but not many have it so I didn't include that. So dent anything that isn't a gif or jpg .    
    $Allow=array("jpg","gif","png");

    If(in_array($file_ext,$Allow)) {

        //Lets do some converting!
        $imgdata=getimagesize($full_server.$album.$file);
        $imgresized=imagecreatetruecolor($thumb_width, $thumb_height);
        
        If($file_ext=="gif") {
            
            $imgsoruce=imagecreatefromgif($full_server.$album.$file);
            
        } Elseif($file_ext=="jpg") {
            
            $imgsoruce=imagecreatefromjpeg($full_server.$album.$file);
            
        } Elseif($file_ext=="png") {
            
            $imgsoruce=imagecreatefrompng($full_server.$album.$file);
            
        } Else {
            
            return false;
            
        }

        imagecopyresized($imgresized, $imgsoruce, 0, 0, 0, 0, $thumb_width, $thumb_height, $imgdata[0], $imgdata[1]);
        
        $new_file=$full_server.$album.$file_name."_thumb.".$file_ext;

        //PHP 4.4.X added safemode check which made me add this here..
        
        $fh=fopen($new_file,'w');
        fclose($fh);
        
        
        If($file_ext=="gif") {
        
            If(!imagegif($imgresized, $new_file)) {
                return false;
            }
            
        } Elseif($file_ext=="jpg") {
            
            If(!imagejpeg($imgresized, $new_file,$jpg_quality)) {
                return false;
            }
            
        } Elseif($file_ext=="png") {
            
            If(!imagepng($imgresized, $new_file)) {
                return false;
            }
            
        }

        
        imagedestroy($imgsoruce);
        imagedestroy($imgresized);
        
        return True;
    }
    
    return false;
}

Link to comment
https://forums.phpfreaks.com/topic/143454-image-overlay-with-gd/
Share on other sites

Your better off using a mask then, especially when using GD. create predefined transpanet masks then over layer the mask on top of your image. That the best way to do it with GD because GD doesn't have the powerful layering options like imagemagick has. If you want example just tell me and I will give you one that will work with all the image types GD supports. For jpg(), the mask won't transparent, but you can set the fade in transparent color to match your background.

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.