graham23s Posted November 22, 2007 Share Posted November 22, 2007 Hi Guys, in 1 of my functions here: ############################################# # Thumbnail code ############################################# function make_smaller_image($filename,$uploaddirectory,$var_loggedinuser) { ## Using GD ## Find out the files extension $extension = explode(".", $filename); $extension = $extension[count($extension)-1]; ## Make all filenames lowercase $extension = strtolower($extension); ## Generate image accrodingly if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") $image = imagecreatefromjpeg($uploaddirectory); elseif($extension == "png") $image = imagecreatefrompng($uploaddirectory); elseif($extension == "gif") $image = imagecreatefromgif($uploaddirectory); ## get it's height and width $imagex = imagesx($image); $imagey = imagesy($image); if($imagey != 0) { /* * lets calculate the aspect ratio and the height * and width for the scaled image. */ $ratio = $imagex / $imagey; if($ratio > 1) { $new_imgthumbx = 150; $new_imgthumby = 150 / $ratio; } else { $new_imgthumbx = (float) 150 * $ratio; $new_imgthumby = 150; } $destinationimage = imagecreatetruecolor($new_imgthumbx,$new_imgthumby); ## create the scaled instance imagecopyresampled($destinationimage,$image,0,0,0,0,$new_imgthumbx,$new_imgthumby,$imagex,$imagey); ## prefix $prefix = "thumb"; ## rename the thumbnail $newimagename = $var_loggedinuser. "-$prefix-" .time(); ## make the file depending on arguments if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") { $createdthumb = imagejpeg($destinationimage,"thumbs/$newimagename.$extension"); } if($extension == 'gif') { $createdthumb = imagegif($destinationimage,"thumbs/$newimagename.$extension"); } if($extension == 'png') { $createdthumb = imagepng($destinationimage,"thumbs/$newimagename.$extension"); } ## return the image return("$newimagename.$extension"); } // end main if } at the end i have to put $newimagename.$extension the first part is the renaming then i add the approriate extension, is there a way to rename it withough having to add the extension myself at the return? i name them like: $newimagename = $var_loggedinuser. "-$prefix-" .time(); graham23s-thumb-112233545.jpg thanks for any help Graham Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 22, 2007 Share Posted November 22, 2007 Where are your brackets? if(.....) { } else {} Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 22, 2007 Author Share Posted November 22, 2007 you mean after this line: if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") thats weird it works well enough hmm Graham Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 22, 2007 Share Posted November 22, 2007 you mean after this line: if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") thats weird it works well enough hmm Graham NEVER EVER leave your statements without the brackets. Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 22, 2007 Author Share Posted November 22, 2007 thanks mate added them, can you tell me how its best to put them in? cheers mate Graham Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 22, 2007 Share Posted November 22, 2007 <?php ############################################# # Thumbnail code ############################################# function make_smaller_image($filename,$uploaddirectory,$var_loggedinuser) { ## Using GD ## Find out the files extension $extension = explode(".", $filename); $extension = $extension[count($extension)-1]; ## Make all filenames lowercase $extension = strtolower($extension); ## Generate image accrodingly if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") { $image = imagecreatefromjpeg($uploaddirectory); } elseif($extension == "png") { $image = imagecreatefrompng($uploaddirectory); } elseif($extension == "gif") { $image = imagecreatefromgif($uploaddirectory); } ## get it's height and width $imagex = imagesx($image); $imagey = imagesy($image); if($imagey != 0) { /* * lets calculate the aspect ratio and the height * and width for the scaled image. */ $ratio = $imagex / $imagey; if($ratio > 1) { $new_imgthumbx = 150; $new_imgthumby = 150 / $ratio; } else { $new_imgthumbx = (float) 150 * $ratio; $new_imgthumby = 150; } $destinationimage = imagecreatetruecolor($new_imgthumbx,$new_imgthumby); ## create the scaled instance imagecopyresampled($destinationimage,$image,0,0,0,0,$new_imgthumbx,$new_imgthumby,$imagex,$imagey); ## prefix $prefix = "thumb"; ## rename the thumbnail $newimagename = $var_loggedinuser. "-$prefix-" .time(); ## make the file depending on arguments if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") { $createdthumb = imagejpeg($destinationimage,"thumbs/$newimagename.$extension"); } if($extension == 'gif') { $createdthumb = imagegif($destinationimage,"thumbs/$newimagename.$extension"); } if($extension == 'png') { $createdthumb = imagepng($destinationimage,"thumbs/$newimagename.$extension"); } ## return the image return("$newimagename.$extension"); } // end main if } ?> Also, what is that you want to do with the extension? If the code works, then just use it, else tell me the problem with renaming the file yourself. Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 22, 2007 Author Share Posted November 22, 2007 Hi Mate, its this bit really return("$newimagename.$extension"); once the file has been named i have to concatenate it with the extension, was wondering if there was a way it would just come back as 1 file rather than me joining: $newimagename.$extension");[/ thanks mate Graham Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 22, 2007 Share Posted November 22, 2007 Hi Mate, its this bit really return("$newimagename.$extension"); once the file has been named i have to concatenate it with the extension, was wondering if there was a way it would just come back as 1 file rather than me joining: $newimagename.$extension");[/ thanks mate Graham Whats wrong with joining them? Its how you put them back as one anyways. ("$newimagename"."$extension");[/ Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 22, 2007 Author Share Posted November 22, 2007 yeah true i just htought there may have been a better way lol it works thats the main thing i guess. cheers Graham Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 22, 2007 Share Posted November 22, 2007 cheers. 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.