Jump to content

Calling function info


graham23s

Recommended Posts

Hi Guys,

 

Just getting started using functions more and more now, but i'm having trouble here is the code:

 

function:

 

     ############################################# 
     # Thumbnail code                            
     #############################################   
     function resize_images($filename,$uploaddirectory,$var_loggedinuser) {  
     
        ## Find out the files extension 
        $ext = explode(".", $filename); 
        $ext = $ext[count($ext)-1]; 
          
        ## random numbers 
        $randomnumber = rand(0,999999999); 
          
          if($ext == "jpg" || $ext == "jpeg")     
           
              $image = imagecreatefromjpeg($uploaddirectory); 
               
          elseif($ext == "png") 
           
              $image = imagecreatefrompng($uploaddirectory); 
               
          elseif($ext == "gif") 
           
              $image = imagecreatefromgif($uploaddirectory); 
               
        ## save the file in %     
        $size = 0.50; 
         
        ## rename the thumbnail 
        $newimagename_thumb = $var_loggedinuser. "-" .time(); 
        $save = "thumbs/$newimagename_thumb.$ext"; 
               
        ## get the files dimensions 
        list($width,$height) = getimagesize($uploaddirectory); 
         
        $modwidth = $width * $size;  
        $modheight = $height * $size;  
        $thumbnail = imagecreatetruecolor($modwidth, $modheight) ;  
        imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);         
        ## imagejpeg($thumbnail, $save, 100);  
         
        if($ext == 'jpg' || $ext == 'jpeg') 
      
        imagejpeg($thumbnail, $save, 100); 
      
        if($ext == 'gif') 
      
        imagegif($thumbnail, $save, 100); 
      
        if($ext == 'png') 
      
        imagepng($thumbnail, $save, 100); 
        
        return($save);
        
        }

 

calling the function:

 

resize_images($filename,$uploaddirectory,$var_loggedinuser);

 

what im having trouble with is, how do i get information FROM the function i need:

 

$newimagename_thumb.$ext

 

this bit of information back from the function to use when displaying the thumbnail not sure how to acomplish this any help would be great guys

 

Cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/76560-calling-function-info/
Share on other sites

a function can be used in any way you want, the return is optional, however seeing as you want it you can say

$var = doafunction();

 

and then $var will contain the return of the doafunction();

 

You could echo it straight out

 

echo doafunction();

 

and it out put it make sense?

Link to comment
https://forums.phpfreaks.com/topic/76560-calling-function-info/#findComment-387746
Share on other sites

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.