Image resizing / renaming

laredo512

Well-known member
Joined
Jan 6, 2004
Messages
88
Location
Far enough to see snow in winter
Hi,

Got a small web project in VB.NET/ASP.NET. The last part I am having trouble with is when a web user uploads and image, I want to be able to resize, watermark and rename it.

Saving it to disk is not a problem, neither is the renaming.

I cant seem to find a decent snippet that will allow me to resize and watermark.

Any suggestions or sites I can go see to achieve this?

Thanks for any input
 
Browing throughout this site and following many links for 5 hours, I have compiled a small solution for VB.NET users so that you would be able to

1. upload an image
2. rename it
3. create a thumbnail
4. save both files

The only thing remaining is to find a way to combine 2 images into one. The second image would be a watermark image. So if anyone has input on this, please let me know.

Thanks


Code:
 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim MyPath, MyName As String
         Display the names in C:\ that represent directories.

        MyPath = "C:\www\tester"                       Set the path.
        MyName = Dir(MyPath, vbDirectory)    Retrieve the first entry.

        If MyName = "" Then    The folder is not there & to be created
            MkDir("C:\www\tester")       Folder created
            span2.InnerHtml = "A Folder is created at the Page_Load"
        End If

    End Sub

    Sub Upload_Click(ByVal Sender As Object, ByVal e As EventArgs)

         Display properties of the uploaded file

        FileName.InnerHtml = MyFile.PostedFile.FileName
        FileContent.InnerHtml = MyFile.PostedFile.ContentType
        FileSize.InnerHtml = MyFile.PostedFile.ContentLength
        UploadDetails.visible = True

         Let us recover only the file name from its fully qualified path at client 

        Dim strFileName As String
        strFileName = MyFile.PostedFile.FileName

        Dim c As String = System.IO.Path.GetFileName(strFileName)  only the attched file name not its path

         Let us Save uploaded file to server at C:\www\tester


        Try
            Dim b As Bitmap
            b = b.FromStream(MyFile.PostedFile.InputStream)

            Dim s As Bitmap create a new bitmap and make a thumbnail of 100 X 100 pixels
            s = b.GetThumbnailImage(100, 100, New Image.GetThumbnailImageAbort(AddressOf tb), IntPtr.Zero)
            s.Save("C:\www\tester\" + "TN_file.jpg")

            MyFile.PostedFile.SaveAs("C:\www\tester\" + "file.jpg")
            addPic(c)

            Span1.InnerHtml = "Your File Uploaded Sucessfully at server as : C:\www\tester" & c & _
" -//- " & FileContent.InnerHtml & "   : file content " & _
" -//- " & FileSize.InnerHtml & "   : file size" & _
" -//- " & FileName.InnerHtml & "   : file name"

        Catch Exp As Exception
            Span1.InnerHtml = Err.Number.ToString & " // " & Err.Description & _
            " // " & Err.Erl.ToString & " // " & Err.Source.ToString & _
            " // " & Err.GetException.ToString & " // "

            UploadDetails.Visible = False
            Span2.Visible = False
        End Try

    End Sub

    Private Function tb() As Boolean 
        Return False
    End Function
 
thanks !!!

heres the same one you had setup to be a robust (is that the right word) procedure



Private Function CreateThumbnail(ByVal MyFile As HtmlInputFile, ByVal file_and_location As String, Optional ByVal Width As Integer = 100, Optional ByVal Height As Integer = 100) As Boolean
Dim strFileName As String
strFileName = MyFile.PostedFile.FileName
Dim c As String = System.IO.Path.GetFileName(strFileName) only the attched file name not its path
Try
Dim b As Bitmap
b = b.FromStream(MyFile.PostedFile.InputStream)
Dim s As Bitmap create a new bitmap and make a thumbnail of 100 X 100 pixels
s = b.GetThumbnailImage(Width, Height, New System.Drawing.Image.GetThumbnailImageAbort(AddressOf tb), IntPtr.Zero)
s.Save(file_and_location)
Return True
Catch Exp As Exception
Return False
End Try
End Function
Private Function tb() As Boolean
Return False
End Function
 
Back
Top