Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: aspupload and aspjpeg not resizing image on upload

  1. #11
    Join Date
    May 2007
    Location
    Eauze, France
    Posts
    175
    Thanks
    10
    Thanked 17 Times in 15 Posts

    Default

    [QUOTE=slippers;23650]I am getting a little confused here, can I resize the image without saving it but still use file.filename (I thought file.filename grabbed the name of the image just uploaded)

    The upload.save method does need to be called - if you omit the path it does a memory save so you can examine the filename, form fields etc before you save the file to disk.

    Try the following - if you reresh the page a few times you should get some new versions.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
    <style type="text/css">
    <!--
    #loading {
        width: 200px;
        height: 100px;
        background-color: #c0c0c0;
        position: absolute;
        left: 50%;
        top: 50%;
        margin-top: -50px;
        margin-left: -100px;
        text-align: center;
    }
    -->
    </style>
    
    <script type="text/javascript">
    <!-- Begin
    document.write('<div id="loading"><br><br>Please wait...</div>');
    window.onload=function(){
        document.getElementById("loading").style.display="none";
    }
    // End -->
    </script>
    </head>
    <body >
    <%
    PathPrefix = Server.MapPath("/Pics/products/") & "\" & Request.Cookies("AdminId") & "-"
    
    ' Create an instance of AspUpload object
    Set Upload = Server.CreateObject("Persits.Upload")
    Upload.ProgressID = Request.QueryString("PID")
    Upload.Save ' >>>>>Save to Memory - Now we can access the filename before we save it to disk.
    
    Set File = Upload.Files(1)
    LeftFN=Left(File.Filename,INSTR(File.Filename,".")-1) '- drop '.jpg'
    
    'Make Path+filename unique
    CT=0
    Path=PathPrefix & LeftFN & ".JPG"
    
    While Upload.FileExists(Path)
    	CT=CT+1
    	Path = PathPrefix & LeftFN & "(" & CT & ").JPG"
    Wend
    
    File.saveas(path)
    
      ' Is this a valid image file?
      If File.ImageType <> "UNKNOWN" Then
    
        ' Create instance of AspJpeg object
        Set jpeg = Server.CreateObject("Persits.Jpeg")
    
        ' Open uploaded file
        jpeg.Open(path)
    
    'only resize if bigger
    if Jpeg.OriginalWidth > 600 then
    	' Resize, preserve aspect ratio
    	Jpeg.Width = 600
    	Jpeg.Height = Jpeg.OriginalHeight * W / Jpeg.OriginalWidth
    end if
    
        jpeg.Save Path
    
    end if
    
    'response.redirect "/admin/products/edit-image/?productpicture=" & Path
    
    %>
    </body>
    </html>
    Last edited by SKILLIT; 10th April 2010 at 04:07 PM. Reason: PathPrefix needed folder seperator.

  2. #12
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    aha, just noticed you posted this. I have just spent the afternoon in the garden properly digesting aspupload and aspjpeg and understand it all now. THank you very much for your help, you certainly sped up my knowledge of all this

    If anyone is reading this wanting to know how to do it, the code above works perfectly apart from a small tweak needed in the resize portion of the code

    Code:
    if Jpeg.OriginalWidth > 600 then
    	' Resize, preserve aspect ratio
    	Jpeg.Width = 600
    	Jpeg.Height = Jpeg.OriginalHeight * W / Jpeg.OriginalWidth
    should be

    Code:
    if Jpeg.OriginalWidth > 600 then
    	' Resize, preserve aspect ratio
    	Jpeg.Width = 600
    	Jpeg.Height = Jpeg.OriginalHeight * 600 / Jpeg.OriginalWidth
    end if

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [AspJpeg] Fetching a unique generated file name
    By Rappie in forum ASP (VBScript)
    Replies: 2
    Last Post: 22nd October 2008, 01:59 PM
  2. Replies: 5
    Last Post: 21st January 2007, 05:11 PM
  3. asp.net image upload
    By creativeworks in forum ASP.NET
    Replies: 3
    Last Post: 27th September 2006, 02:39 AM
  4. ASPUpload Help!
    By chrispont in forum ASP.NET
    Replies: 6
    Last Post: 9th April 2006, 09:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •