Using the ASPJpeg Component
The ASPJpeg script will show you how to use some of the features of the ASPJpeg component to resize and modify .jpg images.
Dim picture, newpicture, cropamount
We define variables that will hold the old picture, the new picture that has been modified, and the amount to crop off of each side of the old picture.
picture = "test.jpg"
This specifies the name of the picture to open which will be modified.
newpicture = "test_new.jpg"
This is the name of the file that the modified picture will be saved as.
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Creates the Jpeg object.
Path = Server.MapPath(picture)
Determines the full path to the picture to be modified.
Jpeg.Open Path
This opens the file to be modified using the full path.
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
Resizes the image to half the size. We specify the new height and width.
Jpeg.Sharpen 1, 150
This sharpens the image. The first number specifies the radius and the second number specifies the amount.
Jpeg.FlipH()
This flips the image on the horizontal.
Jpeg.FlipV()
This flips the image on the vertical.
cropamount = 10
This sets the crop amount variable. This variable will be used to take size off each side.
Jpeg.Crop cropamount, cropamount, Jpeg.Width - cropamount, Jpeg.Height - cropamount
This does the actual cropping.
Jpeg.Save Server.MapPath(newpicture)
This saves the modified image using the full path.
Response.Write "The new picture was written as: " & newpicture
Tells the user that the image was saved.
The rest of the script uses HTML to output the old and new image files.
--Here is the full script, the filename is: aspjpeg.asp--
<%
'Easy CGI Test Script for ASPJpeg
Dim picture, newpicture, cropamount
'name of the picture to open
picture = "test.jpg"
'new name of the changed picture
newpicture = "test_new.jpg"
' Create an instance of AspJpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Compute path to source image
Path = Server.MapPath(picture)
' Open source image
Jpeg.Open Path
' Decrease image size by 50%
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
' Optional: apply sharpening
Jpeg.Sharpen 1, 150
'Flip it on the horizontal
Jpeg.FlipH()
'Flip it on the Vertical
Jpeg.FlipV()
'amount to crop off each side
cropamount = 10
'Crop pixels off of each edge
Jpeg.Crop cropamount, cropamount, Jpeg.Width - cropamount, Jpeg.Height - cropamount
' Create thumbnail and save it to disk
Jpeg.Save Server.MapPath(newpicture)
Response.Write "The new picture was written as: " & newpicture
'output the pictures to the web page
%>
<HTML>
OLD
<IMG SRC="<%Response.Write picture%>">
NEW
<IMG SRC="<%Response.Write newpicture%>">
</HTML>
--End Script--
More detailed examples of the ASPJpeg Component can be found at: http://www.aspupload.com/aspjpeg.html
<< Back |