Rank: Member
Groups: Member
Joined: 1/12/2005(UTC) Posts: 2
|
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">
'*************************************************************************************************************************'
' Norbornano Script WITH IMAGE RESIZE FROM SERVER SIDE '
' Mailto: webmaster@zeroipocrisia.com '
' WWW: http://www.zeroipocrisia.com '
'*************************************************************************************************************************'
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 'Define Sub Page
Dim MyConnection As New OleDbConnection(StrConnStrings) 'Define Connection
MyConnection.Open 'Open Connection
Dim MyCommand As New OleDbCommand() 'Create OleDbCommand
MyCommand.Connection = MyConnection 'Create Connection
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") 'Get author name from attached HTML form
Dim intFileCount As Integer = CInt(Request.Form("FileCount")) 'Get total number of uploaded files
Dim I As Integer, SourceFile As HttpPostedFile, ThumbnailFile As HttpPostedFile
'We iterate through the uploaded files and save them and appropriate data
For I=1 To intFileCount
'Get source image and save it to disk
SourceFile = Request.Files("SourceFile_" & I)
Dim strFileName As String = Path.GetFileName(SourceFile.FileName)
'Check whether file with such name already exists and if so,
'construct safe filename name (to avoid collision)
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))
'*************************************************************************************************************************'
' Get first thumbnail AND RESIZE IT TO 40 X 40 PIXEL and save it to disk '
'*************************************************************************************************************************'
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()
'*************************************************************************************************************************'
' Get a second thumbnail AND RESIZE IT TO 100 X 100 PIXEL and save it to disk '
'*************************************************************************************************************************'
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
'*************************************************************************************************************************'
' BOLO KOTOGNA Image Squared Add Code - THIS SERVER SIDE CODE RESIZE THUMBNAIL TO A 40 X 40 AND 100 X 100 PIXEL '
'*************************************************************************************************************************'
ParameterName.Value = strFileName 'Save description to the database
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 'Do not forget to close the connection.
End Sub
</script>
Edited by user Thursday, February 14, 2008 5:16:59 PM(UTC)
| Reason: Not specified
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.