Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Upload an Image and Resize it

Options
  • 24-07-2006 1:20pm
    #1
    Registered Users 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 Posts: 3,057 ✭✭✭kjt


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


  • Registered Users 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