[code] Dynamic signature

Results 1 to 2 of 2
  1. #1
    Moooooooooooooooo alphaest is offline
    Grand MasterRank
    Jul 2006 Join Date
    WorldLocation
    2,026Posts

    Cool [code] Dynamic signature

    How the sig will look like, just look at my sig.

    So that this thread wont grow to a helpdesk then people who dont know what php and ftp is should not try this code.

    Needed:
    - A accessible FTP server (public ones which have a webserver with php on it should do it prolly)
    - PHP
    - GD 2 or newer library in php (just see if the function imagecreatetruecolor works)
    - header send - the public servers that put some crap in the head of the file or any other ad's and stuff arent suitable
    - basic php knowledge

    Code:

    PHP Code:
    <?php
    $path
    ="data/";


    $files=array();
    $dirp = @opendir($path);
    if (
    $dirp){
        
    $count 0;
        while (
    $file_name readdir($dirp))
        {
            if ((
    $file_name != ".") && ($file_name != "..") && (!is_dir($path.$file_name)) && strpos($file_name,"_log")===false){
                
    $files[] = $path.$file_name;
                
    $count++;
            }
        }
        
    closedir($dirp);
    }


    $pic2 $files[rand(0,count($files)-1)]; // take a random image from the list

    header("Content-type: image/jpeg");


    /////////////////////////////////////////////////////////////////////////////////////////////////////
    $picsize=getimagesize($pic2);
    $source_x $picsize[0];
    $source_y  $picsize[1];


    $kvaliteet 85// quality, dont use over 85, pointless

    $maxw 500// maximum width for the sig, the image will be resized to this width
    $crop 150// maximum height for the sig, image will be cropped from teh centre

    $siz $picsize;
    if ((
    $siz[0] > $maxw))
    {
        
    $neww $maxw;
        
    $x $siz[0]/$maxw;
        
    $newh $siz[1]/$x;
    }
    else
    {
        
    $neww $siz[0];
        
    $newh $siz[1];
    }

    $ext strtolower(strrchr($pic2,"."));
    switch(
    $ext){ 
        case 
    ".gif"$source_id ImageCreateFromGIF$pic2 ); break; 
        case 
    ".jpg"$source_id ImageCreateFromJPEG$pic2 ); break; 
        case 
    ".png"$source_id ImageCreateFromPNG$pic2 ); break; 
        default: 
    $source_id ImageCreateFromJPEG$pic2 ); break;



    $target_id=imagecreatetruecolor($neww$newh);
    $target_id2=imagecreatetruecolor($neww$crop);
    $miniS newSize($picsize,100,120);
    $mini imagecreatetruecolor($miniS[0], $miniS[1]);
    $crophS $newh/2-$crop/2;
    imagecopyresampled$target_id$source_id0000$neww$newh$source_x$source_y ); 
    imagecopyresampled$target_id2$target_id000$crophS$neww$crop$neww$crop ); 
    imagecopyresampled$mini$source_id0000$miniS[0], $miniS[1], $source_x$source_y); 
    $target_id2 image_overlap($target_id2,$mini);

    $waterM ImageCreateFromGIF("waterm.gif"); // watermark image file which will be overlapped 

    imagecolorset($waterM,0,0xA0,0xFF,0xE0); // set the first colo from the palette to this new color
    imagecolorset($waterM,2,0x00,0xD0,0xA0); // and second
    $target_id2 image_overlap($target_id2,$waterM,1,55);


    imagejpeg ($target_id2,"",$kvaliteet);

    imagedestroy($target_id);
    imagedestroy($target_id2);
    imagedestroy($source_id);
    imagedestroy($mini);
    imagedestroy($waterM);

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function image_overlap($background$foreground,$zero=0,$trans=60)
    {
       
    $insertWidth imagesx($foreground);
       
    $insertHeight imagesy($foreground);

       
    $imageWidth imagesx($background);
       
    $imageHeight imagesy($background);

        if(!
    $zero){
            
    $overlapX $imageWidth-$insertWidth-5;
            
    $overlapY $imageHeight-$insertHeight-30;
        }else{
            
    $overlapX=0;
            
    $overlapY=$imageHeight-$insertHeight;
        }
      
    // imagecolortransparent($foreground,imagecolorat($foreground,0,0));
       
    imagecopymerge($background,$foreground,$overlapX,$overlapY,0,0,$insertWidth,$insertHeight,$trans);
       return 
    $background;
    }
    function 
    newSize($siz,$maxw,$maxh)
    {
        if ((
    $siz[0] > $maxw) || ($siz[1] > $maxh))
        {
            if ((
    $siz[0]/$maxw) > ($siz[1]/$maxh))
            {
                
    $neww $maxw;
                
    $x $siz[0]/$maxw;
                
    $newh $siz[1]/$x;
            }
            if ((
    $siz[0]/$maxw) < ($siz[1]/$maxh))
            {
                
    $newh $maxh;
                
    $x $siz[1]/$maxh;
                
    $neww $siz[0]/$x;
            }
            if ((
    $siz[0]/$maxw) == ($siz[1]/$maxh))
            {
                
    $neww $maxw;
                
    $newh $maxh;
            }
        }
        else
        {
            
    $neww $siz[0];
            
    $newh $siz[1];
        }
        return array(
    $neww,$newh);
    }

    ?>
    sorry for the bad look of the code but it was just some file that got edited 1000 times for different purposes.


    Images are located in ./data/ folder, waterm.gif is in the same folder.
    Anyway, just look at the code and u'll get what its doing.


    :drinks_no

    Cheers,

    AlphA


  2. #2
    No One Knows ! ☠RockAngeL☠ is offline
    Grand MasterRank
    Apr 2007 Join Date
    ☮/UAE.phpLocation
    3,184Posts

    Re: [code] Dynamic signature

    its not Working :\ , maybe becuse am using WAMP5?

    or i need PHP in order?



Advertisement