Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Upload an Image and Resize it

  • 24-07-2006 01:20PM
    #1
    Registered Users, Registered Users 2 Posts: 312 ✭✭


    hey i want to be able to allow users to upload images, but i want to control the size that they will appear as. for example if a user uploads an image 800x600 that is going to be to big on the screen so i want it to resize it to 400x300 for example.
    i am biulding the site in ASP


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m




  • Closed Accounts Posts: 1,956 ✭✭✭layke




  • Registered Users, Registered Users 2 Posts: 3,057 ✭✭✭kjt


    dshakey wrote:
    i am biulding the site in ASP
    Good to know.
    Google is your friend.


  • Registered Users, Registered Users 2 Posts: 706 ✭✭✭DJB


    Hi David,

    There's loads of ways to do this with different components out there. Just search for ASP Upload Component and/or ASP Image Component. Personally, I use the following:

    - ASP Smart Upload (free) to get the files onto the server, then
    - ASP Smart Image (€99 per server) to process the images, e.g. resize, create thumbnails, etc.

    www.aspsmart.com

    Here's how easy it is... this is a block of code to upload 5 images and process them:
    <%
    IF Request("upload") = "y" THEN
    
    	'Create SmartUpload and SmartImage Object
    		Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
    		Set oSmartImg = Server.CreateObject("aspSmartImage.SmartImage")
    	
    	'Upload the files
    		mySmartUpload.Upload
    	
    	'Get last photo id
    		sSQL = "SELECT * FROM tblPhotos ORDER BY phID DESC"
    		CALL OpenRS(rsPhotoID, sSQL, sDatabase)
    		
    		intLastPhotoID = rsPhotoID("phID")
    		
    		CALL CloseRS(rsPhotoID)
    	
    	'Loop through files
    		For each file In mySmartUpload.Files
    	
    		'Only if the file exist
    			If not file.IsMissing Then
    				intCount = intCount + 1
    				
    				'New File Name
    					sNewFileName = lcase("ph" & (intLastPhotoID + intCount) & "." & file.FileExt)
    					sHQFileLocation = "images/hq/" 'high quality
    					sLGFileLocation = "images/lg/" 'resized image
    					sTNFileLocation = "images/tn/" 'thumbnail image
    				
    				
    				'Save the file to the HQ folder
    					file.SaveAs(sHQFileLocation & sNewFileName)
    				
    				'Create large file with 225 height and save to lg folder
    					oSmartImg.openFile cstr(sHQFileLocation & sNewFileName)
    					oSmartImg.Resample 0,225
    					Call oSmartImg.SaveFile(sLGFileLocation & sNewFileName)
    				
    				'Create small file with 90 height and save to tn folder
    					oSmartImg.openFile cstr(sHQFileLocation & sNewFileName)
    					oSmartImg.Resample 0,90
    					Call oSmartImg.SaveFile(sTNFileLocation & sNewFileName)
    				
    				'Save the new file in the database with the listing id
    				sSQL = "INSERT INTO tblPhotos(phFile)"
    				sSQL = sSQL &" VALUES "
    				sSQL = sSQL &"('"& sNewFileName &"')"
    				CALL InsertRec(sName, sSQL, sDatabase)
    
    			End If
    		Next
    	
    	'Kill the SmartASP Objects
    		Set mySmartUpload = Nothing
    		Set oSmartImg = Nothing
    	
    	'Redirect to display page
    		Response.Redirect("photos.asp")
    END IF
    

    The form I have on the page just has 5 file input boxes that post to this. I use tmt validator (http://www.massimocorner.com/validator/) to check file sizes, widths, heights, etc. before the upload occurs. You can also do this in ASP.

    Hope that helps,

    Rgds,

    Dave


Advertisement