graham23s Posted November 8, 2007 Share Posted November 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 8, 2007 Share Posted November 8, 2007 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.