• home
  • forum
  • my
  • kt
  • download
  • ASP image resize and convert

    Author: 2007-06-24 20:16:58 From:

      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.
          You can see this short code with Huge ASP file upload live at Upload with resize page.
    view plaincopy to clipboardprint?
    1. 'Resize image using ASP/VBS   
    2. '2007 www.motobit.com    
    3. Function ResizeImage(FileName, OutFormat, Width, Height)   
    4.   Dim Chs, chConstants   
    5.   'Create an OWC chart object   
    6.   Set Chs = CreateObject("OWC10.ChartSpace")   
    7.      
    8.   Set chConstants = Chs.Constants   
    9.      
    10.   'Set background of the chart   
    11.   Chs.Interior.SetTextured FileName, chConstants.chStretchPlot, , chConstants.chAllFaces   
    12.   Chs.border.color = -3   
    13.   
    14.   'Do something with border   
    15.   'Chs.border.color = &H0000FF   
    16.   'Chs.border.Weight = 3   
    17.   
    18.   'export the picture to a file   
    19.   'Chs.ExportPicture OutFileName, OutFormat, Width, Height   
    20.      
    21.   'or return it as a binary data for BinaryWrite   
    22.   ResizeImage = Chs.GetPicture(OutFormat, Width, Height)   
    23. End Function  
    24.   

    Upload and image resize sample

    Image to resize:

          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().
    1. 'Set timeout to 30 minutes   
    2. Server.ScriptTimeout = 1800   
    3.   
    4. 'Set an upload limit to 5MB   
    5. Form.SizeLimit = 5*&H100000   
    6.   
    7. 'Set the destination path - Path to store uploaded files.   
    8. Dim DestinationPath: DestinationPath = Form.WindowsTemp & "\upload\"  
    9.   
    10. Const fsCompletted  = 0   
    11.   
    12. If Form.State = fsCompletted and len(Form("Image").FileName) >0 Then 'Completted   
    13.   'was the Form successfully received?   
    14.      
    15.     Form("Image").Save DestinationPath   
    16.        
    17.     Dim TempFileName, OutFormat, Width, Height   
    18.     TempFileName = DestinationPath & Form("Image").FileName   
    19.     OutFormat = Form("OutFormat")   
    20.     Width = clng(Form("Width"))   
    21.     if Width>8000 then Width = 8000   
    22.     Height = clng(Form("Height"))   
    23.     if Height>8000 then Height = 8000   
    24.        
    25.     'Export the picture from the ASP script   
    26.     response.ContentType = "image/" & OutFormat   
    27.     response.binarywrite ResizeImage(TempFileName, OutFormat, Width, Height)   
    28.   
    29.     createobject("Scripting.FileSystemObject").DeleteFile TempFileName    
    30.     response.end   
    31. ElseIf Form.State > 10 then   
    32.   Const fsSizeLimit = &HD   
    33.   Select case Form.State   
    34.     case fsSizeLimit: response.write  ".."  
    35.     case else response.write ".."  
    36.   end Select  
    37. End If'Form.State = 0 then   
    ?/td>
     
    If you like this page, please include next link on your pages:
    <A
     Href="http://www.motobit.com/tips/detpg_asp-resize-image/"
     Title="Short sample of using Office web
      components to resize and convert
      image to another format"
    >ASP image resize and jpg/gif/png convert, free VBScript code</A>

    discuss this topic to forum

    relation tutorial

    No relevant information

    New

    Hot