Rank: Member Groups: Member
Joined: 1/13/2005 Posts: 2 Points: 0
|
I asked this forum one week ago to resolve this kind of problem ( create a squared thumbnails)............but a moderator tell me that image uploader can't do that THIS IS A SERVER SIDE SOLUTION FOR ALL THAT HAVE THIS PROBLEM..... GOOD JOB TO ALL OF US Code:
<%@ Page Language="vb" AutoEventWireup="false" Debug="true" enableSessionState="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ OutputCache Duration="1" VaryByParam="None" %>
<script language="VB" runat="server">
Private strGalleryPath = "../web_images/"
Private StrConnStrings As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../database/Demo.mdb")
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyConnection As New OleDbConnection(StrConnStrings)
MyConnection.Open
Dim MyCommand As New OleDbCommand()
MyCommand.Connection = MyConnection
MyCommand.CommandText = "INSERT INTO [File](Name, Width, Height, Author, Description) " & "VALUES (?, ?, ?, ? ,?)"
Dim ParameterName As OleDbParameter = MyCommand.Parameters.Add("@Name", OleDbType.VarChar)
Dim ParameterWidth As OleDbParameter = MyCommand.Parameters.Add("@Width", OleDbType.Integer)
Dim ParameterHeight As OleDbParameter = MyCommand.Parameters.Add("@Height", OleDbType.Integer)
Dim ParameterAuthor As OleDbParameter = MyCommand.Parameters.Add("@Author", OleDbType.VarChar)
Dim ParameterDescription As OleDbParameter = MyCommand.Parameters.Add("@Description", OleDbType.VarChar)
ParameterAuthor.Value = Request.Form("Author")
Dim intFileCount As Integer = CInt(Request.Form("FileCount"))
Dim I As Integer, SourceFile As HttpPostedFile, ThumbnailFile As HttpPostedFile
For I=1 To intFileCount
SourceFile = Request.Files("SourceFile_" & I)
Dim strFileName As String = Path.GetFileName(SourceFile.FileName)
Dim strNewFileName As String = strFileName
Dim J As integer = 1
While File.Exists(Server.MapPath(strGalleryPath & strNewFileName))
strNewFileName = J & "_" & strFileName
J = J + 1
End While
strFileName = strNewFileName
SourceFile.SaveAs (Server.MapPath(strGalleryPath & strFileName))
Dim InputBitmap as Bitmap = new Bitmap(Server.MapPath(strGalleryPath & strFileName))
Dim newWidth as integer = 40
Dim newHeight as integer = 40
Dim OutputBitmap as Bitmap = new Bitmap(InputBitmap, newWidth, newHeight)
Response.Clear()
Response.ContentType="image/jpeg"
OutputBitmap.Save(Server.MapPath(strGalleryPath & "../thumbnail_images/" & strFileName ), ImageFormat.Jpeg)
OutputBitmap.Dispose()
InputBitmap.Dispose()
Dim Categoria As string = Request.Form("Author")
Dim Descrizione As string = Request.Form("Description_" & I)
If Categoria = Descrizione then
Dim InputBitmapX as Bitmap = new Bitmap(Server.MapPath(strGalleryPath & strFileName))
Dim newWidthX as integer = 100
Dim newHeightX as integer = 100
Dim OutputBitmapX as Bitmap = new Bitmap(InputBitmapX, newWidthX, newHeightX)
Response.Clear()
Response.ContentType="image/jpeg"
OutputBitmapX.Save(Server.MapPath(strGalleryPath & "../group_photos/" & strFileName ), ImageFormat.Jpeg)
OutputBitmapX.Dispose()
InputBitmapX.Dispose()
end if
ParameterName.Value = strFileName
ParameterWidth.Value = CInt(Request.Form("Width_" & I))
ParameterHeight.Value = CInt(Request.Form("Height_" & I))
ParameterDescription.Value = Request.Form("Description_" & I)
MyCommand.ExecuteNonQuery
Next
MyConnection.Close
End Sub
</script>
|