This sample uses Chart object from
OWC library to resize any image and convert the image to a specified format (.jpg, .png, .bmp, .gif...). The image is placed to the chart using
SetTextured property, which can load any image file from a disk. Then you can use border property to set some frame around the image (or left the frame blank) and export the picture using
ExportPicture method to a disk or get the picture as a binary data for BinaryWrite using
GetPicture method.
- 'Resize image using ASP/VBS
- '2007 www.motobit.com
- Function ResizeImage(FileName, OutFormat, Width, Height)
- Dim Chs, chConstants
- 'Create an OWC chart object
- Set Chs = CreateObject("OWC10.ChartSpace")
-
- Set chConstants = Chs.Constants
-
- 'Set background of the chart
- Chs.Interior.SetTextured FileName, chConstants.chStretchPlot, , chConstants.chAllFaces
- Chs.border.color = -3
-
- 'Do something with border
- 'Chs.border.color = &H0000FF
- 'Chs.border.Weight = 3
-
- 'export the picture to a file
- 'Chs.ExportPicture OutFileName, OutFormat, Width, Height
-
- 'or return it as a binary data for BinaryWrite
- ResizeImage = Chs.GetPicture(OutFormat, Width, Height)
- End Function
Upload and image resize sample
Next piece of VBScript code if from the live resize sample and demonstrates the ResizeImage function. The source gif, jpeg or png image from upload is saved to a temp folder. The code reads data for the resize - new width and height and out format and then calls response.binarywrite ResizeImage().
- 'Set timeout to 30 minutes
- Server.ScriptTimeout = 1800
-
- 'Set an upload limit to 5MB
- Form.SizeLimit = 5*&H100000
-
- 'Set the destination path - Path to store uploaded files.
- Dim DestinationPath: DestinationPath = Form.WindowsTemp & "\upload\"
-
- Const fsCompletted = 0
-
- If Form.State = fsCompletted and len(Form("Image").FileName) >0 Then 'Completted
- 'was the Form successfully received?
-
- Form("Image").Save DestinationPath
-
- Dim TempFileName, OutFormat, Width, Height
- TempFileName = DestinationPath & Form("Image").FileName
- OutFormat = Form("OutFormat")
- Width = clng(Form("Width"))
- if Width>8000 then Width = 8000
- Height = clng(Form("Height"))
- if Height>8000 then Height = 8000
-
- 'Export the picture from the ASP script
- response.ContentType = "image/" & OutFormat
- response.binarywrite ResizeImage(TempFileName, OutFormat, Width, Height)
-
- createobject("Scripting.FileSystemObject").DeleteFile TempFileName
- response.end
- ElseIf Form.State > 10 then
- Const fsSizeLimit = &HD
- Select case Form.State
- case fsSizeLimit: response.write ".."
- case else response.write ".."
- end Select
- End If'Form.State = 0 then