Using aspupload,aspjpeg to realize image upload automatically generate thumbnails and add watermark _ Application Techniques

Source: Internet
Author: User

Today in the Webmaster station to see a netizen to write the photo album program, the function is quite simple, see he used the aspjpeg to generate thumbnails, not to recall using aspupload upload, so spent one hours to perfect his code.

The following code has a simple comment, if you do not understand, please look at AspJpeg and AspUpload documentation (E, hope to have psychological preparation), can not understand the ask me.

Here's the code:

Copy Code code as follows:

<%
If session ("admin") <> ' on ' then
Response.Redirect "Login.asp"
End If
%>
<!--#include file= "config.asp"-->
<!--#include file= "mdb/conn.asp"-->

<%
Set Upload = Server.CreateObject ("Persits.upload")

Filepath=server.mappath (".")

Count = Upload.Save (filepath&bigphotopath) ' Big picture

Smallfilepath=filepath & Smallphotopath

For each File in Upload.files

Set Jpeg = Server.CreateObject ("Persits.jpeg")
Jpeg.open (File.path)

bigfp=bigphotopath& (file.filename) ' Large graph relative path
sfp=smallphotopath& "S_" & (file.filename) ' Small map relative path
Filesize=file.size ' ready to write to database


' Start to judge which side is the long edge, zoom with the long edge, and generate a small figure
Imgwidth=jpeg.originalwidth
Imgheight=jpeg.originalheight

If Imgwidth>=imgheight and imgwidth>120 then
jpeg.width=150
jpeg.height=jpeg.originalheight/(jpeg.originalwidth/150)
End If
If Imgheight>imgwidth and imgheight>113 then
jpeg.height=113
jpeg.width=jpeg.originalwidth/(jpeg.originalheight/113)
End If
Jpeg.sharpen 1, 130
Jpeg.save (smallfilepath& "S_" &file.filename)


' Add a watermark to the larger image (only large image watermark)
Jpeg.open Server.MapPath ("&BigFP&")

Jpeg.Canvas.Font.Color = &hff0000
Jpeg.Canvas.Font.Family = "Courier New"

Jpeg.Canvas.Pen.Color = &h000000
Jpeg.Canvas.Pen.Width = 2

Jpeg.Canvas.Brush.Solid = False
Jpeg.Canvas.Font.BkMode = "Opaque" Handles smoothing

Jpeg.Canvas.PrintText, "www.LuanLuan.cn"
' Jpeg.Canvas.DrawBar 1, 1, 100, 100

Jpeg.save Server.MapPath (BIGFP)
Next

strsql= insert INTO Desktop ([Name],typeid,zhuanti,jj,[time],imgh,imgw,filesize,url,surl) VALUES (' & Upload.form ("name") & "', '" &upload.form ("typeID") & "', '" &upload.form ("Zhuanti") & "', '" & Upload.form ("Photointro") & "', '" &now () & "', '" &imgheight& "', '" &imgwidth& "', '" & FileSize & "', ' &BigFP&" ', ' "&SFP&" "
Conn.execute strSQL

Set Upload=nothing ' Delete Object
Typeid=request.querystring ("typeID")
Response.Write "<script language=javascript>alert (' File upload success, return! ');"
Response.Write "This.location.href= ' addfile.asp?typeid=" &typeid& "';</script>"

function HTMLEncode2 (fstring)
fstring = Replace (fstring, CHR (13), "")
fstring = Replace (fstring, CHR (a) & CHR (a), "</P><P>")
fstring = Replace (fstring, CHR (), "<BR>")
HTMLEncode2 = fstring
End Function
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.