In this article I have created thumbnails from large images using coding. This code will help how to make thumbnail images before to upload on the server You can specify the size like height and width of the thumbnail images.
you can save thumbnail images in thumbnail folder and if you need to display the full image after click on the thubnail then you can save full image in image folder..
its all about your logic and what you wants to do.
hope it will help you…
( i have coded in c# too)
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Image
Imports System.Drawing.Imaging
Partial Class Default2
Inherits System.Web.UI.Page
Public Function ThumbnailCallback() As Boolean
Return (False)
End Function
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
If img_upload.PostedFile.ContentLength > 0 Then
Dim UploadedFileName As String
UploadedFileName = img_upload.PostedFile.FileName
img_upload.PostedFile.SaveAs(Request.PhysicalApplicationPath & “images/” & UploadedFileName)
Dim size As Image = Image.FromFile(Request.PhysicalApplicationPath & “images/” & UploadedFileName)
Dim h As Int32 = size.Height
Dim w As Int32 = size.Width
‘ You can check the size of the image after upload on the server if that file according to yur dimension then it will submit and will create the thumbnail of the images other wise it will delete from the server.
If (w >= 300 And w <= 1024) And (h >= 30 And h <= 768) Then Label1.Text = “Submit” Else Label1.Text = “Error” size.Dispose() ‘ the image is not in actual range of size then delete it from images folder File.Delete(Server.MapPath(“images”) + “/” + UploadedFileName) Exit Sub End If Try ‘Read in the image filename whose thumbnail has to be created Dim imageurl As String = UploadedFileName ‘Read in the width and height Dim height As Int32 = 175 Dim width As Int32 = 180 If (imageurl.IndexOf(“/”) >= 0) Or (imageurl.IndexOf(“\\”) > 0) Then
Response.End()
End If
imageurl = “images\” + imageurl
Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(imageurl))
Dim dummyCallBack As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ‘Delegate will call the method ThumbnailCallback
Dim thumbNailImg As System.Drawing.Image = fullSizeImg.GetThumbnailImage(width, height, dummyCallBack, IntPtr.Zero)
‘We need to create a unique filename for each generated image
Dim MyDate As DateTime = DateTime.Now
Dim MyString As String = UploadedFileName
‘Save the thumbnail in Png format. You may change it to a diff format with the ImageFormat property
thumbNailImg.Save((Request.PhysicalApplicationPath & “Thumb_images\”) + MyString, ImageFormat.Jpeg) ‘ for imageformat add ”Imports System.Drawing.Imaging
thumbNailImg.Dispose()
Catch ex As Exception
Label.text =”error message”
End Try
Else
End If
End Sub
End Class
With Regards
Vik



Recent Comments