Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: aspupload and aspjpeg not resizing image on upload

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

    Default aspupload and aspjpeg not resizing image on upload

    I am using aspupload and aspjpeg to upload an image, resize to 500px width (with relative height).

    The image is uploading fine but isn`t getting resized. I have had a reply from Persists who make aspjpeg and they said my code looks fine.

    Can someone have a look please?

    Many thanks

    Code:
    <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 >
     <%
     Set Upload =  Server.CreateObject("Persits.Upload.1")
     
     path =  Server.MapPath("/images/products/")
     
                 Count =  Upload.Save(Path)
     
                 Set File =  Upload.Files("FILE1")
     
     
                 ' Create instance of  AspJpeg
     Set Jpeg =  Server.CreateObject("Persits.Jpeg")
     
     ' Open source image
     jpeg.Open( File.Path )
     
     ' New width
     W = 500
     
     ' Resize, preserve aspect  ratio
     Jpeg.Width = W
     Jpeg.Height = Jpeg.OriginalHeight * W /  Jpeg.OriginalWidth
     
     ' create thumbnail and save it to  disk
     SavePath = Path &  File.ExtractFileName
     
     ' AspJpeg always generates thumbnails in JPEG  format.
         ' If the original file was not a JPEG, append .JPG  ext.
         If UCase(Right(SavePath, 3)) <> "JPG"  Then
           SavePath = SavePath &  ".jpg"
         End If
     
         jpeg.Save SavePath
     
     
     response.write "You may now close this  window"
     
     %>
     </body>
     </html>

  2. #2
    Join Date
    Mar 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    This is a guess because I haven't tested the theory, but...

    When you Set File = Upload.Files("FILE1") , I think this is refering to the file in memory, rather than the file you have just saved to disk. You then do the resizing and it saves back to memory.

    Try loading the file you just saved to disk into ASPJpeg, do the resizing, then save it.

    No idea if it will work, but maybe worth a shot.

    Cheers
    Dan

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

    Default

    I think that you need to save the upoloaded file to memory fiest [File.SaveAsVirtual "/Pics/" & FName]
    Here is some working code that saves and resizes. [If it is an index photo it saves two sizes of tghe picture]/

    <%
    Set Upload = Server.CreateObject("Persits.Upload")
    ' Use AspJpeg to resize image
    Set Jpeg = Server.CreateObject("Persits.Jpeg")

    ' Capture and save uploaded image to memory
    Upload.OverwriteFiles = True

    On error resume next
    Count = Upload.Save
    If Err <> 0 Then
    Response.Write("error " & Err & " occured, Please try reducing the filesize.")
    Err.clear
    End If
    on error goto 0

    ' Compute path to source image
    FName = "00000" & Upload.Form("Property") & Upload.Form("Photo") & ".jpg"
    FName= Right(FName,10)
    FName2 = "00000" & Upload.Form("Property") & "0" & ".jpg"
    FName2= Right(FName2,10)
    Photo=Upload.Form("Photo")

    For Each File in Upload.Files
    If File.ImageType = "JPG" Then
    File.SaveAsVirtual "/Pics/" & FName

    Session("Property") = Upload.Form("Property")

    ' Compute path to source image
    Path = Server.MapPath("/Pics/" & FName)
    Jpeg.Open Path
    'Jpeg.Sharpen 1, 120
    Jpeg.Interpolation = 2
    Jpeg.PreserveAspectRatio = True
    Jpeg.Progressive = True
    select case Upload.Form("Photo")
    Case "A","B","C","D","E","F","G","H","I"
    Jpeg.Width = 180
    If Jpeg.Height > 180 Then Jpeg.Height = 180
    Case Else
    Jpeg.Width = 320
    If Jpeg.Height > 320 Then Jpeg.Height = 320
    End Select
    Jpeg.Save Server.MapPath(".") & "\Pics\" & Fname

    If Photo = "1" Then
    Jpeg.Width = 150
    Jpeg.Height = 112
    If Jpeg.Width > 160 Then Jpeg.Width = 160
    Jpeg.Save Server.MapPath(".") & "\Pics\" & FName2
    End If

    Response.Write("Your image has been sucessfully uploaded. View it here, if its not the picture you expected to see, click the 'Refresh Page' button below.<br><br>")
    Session("Pic")=vbtrue
    %>

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

    Default

    Thanks guys you were correct, when I saved it to disk then reopened it all works perfectly fine.

    Do we know what version of aspjpeg and aspupload the servers are running? Whilst on the persists website I noticed lots of the features they have came in at certain versions.

  5. #5
    Join Date
    Apr 2005
    Location
    Bucks. UK
    Posts
    223
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default

    Hi
    Helium appears to be running v2.0.0.1 you can check with the following code:
    Code:
    <%
    ' Create instance of AspJpeg
    Set Jpeg = Server.CreateObject("Persits.Jpeg")
    response.write "AspJpeg v" & Jpeg.Version
    %>
    Regards
    Keith

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

    Default

    Thanks that's great, guess I should have tried .Version

    One last thing I hope you can help me with, I want to add an ID value to the images uploaded and also ensure the saved version is a unique name. I can use SaveUnique (http://www.aspjpeg.com/object_aspjpeg.html#SaveUnique) instead of save to get the unique filename, but how do I grab this back?

    So for example if someone (their ID is say 33) uploads 'foobar.jpg' it needs to call the file 33-foobar.jpg, check if they have uploaded a file with same name, if they have then rename again to 33-foobar1.jpg . I then need to put this final name into a variable so I can pass back to the form.

    Is this all possible with aspupload?

    Here is my code as it stands, this code uploads the image, resizes if needs to and sends back the name to my page once complete.

    Code:
    <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 >
    <%
    ' Create an instance of AspUpload object
    Set Upload = Server.CreateObject("Persits.Upload")
    
    ' Compute path to save uploaded files to
    Path = Server.MapPath("/images/products/")
    
    ' Capture uploaded file. Return the number of files uploaded
    Count = Upload.Save(Path)
    
    If Count = 0 Then
      Response.Write "No images saved."
      Response.End
    Else
      ' Obtain File object representing uploaded file
      Set File = Upload.Files(1)
    
      ' 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( File.Path )
    
    'onl resize if bigger
    if Jpeg.OriginalWidth > 600 then
    
    
    W = 600
    
    ' Resize, preserve aspect ratio
    Jpeg.Width = W
    Jpeg.Height = Jpeg.OriginalHeight * W / Jpeg.OriginalWidth
    
    end if
                    
                    
    
        SavePath = Path & "\" & File.ExtractFileName
    
        ' AspJpeg always generates thumbnails in JPEG format.
        ' If the original file was not a JPEG, append .JPG ext.
        If UCase(Right(SavePath, 3)) <> "JPG" Then
          SavePath = SavePath & ".jpg"
        End If
    
        jpeg.Save SavePath
    
    end if
    end if
    
    'Response.Write("Your image has been sucessfully uploaded. You can now close this window.")
    response.redirect "/admin/products/edit-image/?productpicture=" & File.ExtractFileName
    
    
    %>
    </body>
    </html>

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

    Default

    Thats quite easy.

    ActualNameUsed=SaveUnique SavePath

    If you wanted to know if the file existed before you saved it you could use the filing System Object to see.

    E.g.
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(SavePath) Then
    FExists = vbTrue
    Else
    FExists = vbFalse
    End If

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

    Default

    I think I have been working for too long but I am failing to get this

    Code:
    <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 >
    <%
    ' Create an instance of AspUpload object
    Set Upload = Server.CreateObject("Persits.Upload")
    
    Upload.ProgressID = Request.QueryString("PID")
    
    ' Compute path to save uploaded files to
    Path = Server.MapPath("/images/products/")
    
    ' Capture uploaded file. Return the number of files uploaded
    Count = Upload.Save(Path)
    
    
      ' Obtain File object representing uploaded file
      Set File = Upload.Files(1)
    
      ' 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( File.Path )
    
    'onl resize if bigger
    if Jpeg.OriginalWidth > 600 then
    
    
    W = 600
    
    ' Resize, preserve aspect ratio
    Jpeg.Width = W
    Jpeg.Height = Jpeg.OriginalHeight * W / Jpeg.OriginalWidth
    
    end if
                    
                    
    
        SavePath = Path & "\" & File.ExtractFileName
    
        ' AspJpeg always generates thumbnails in JPEG format.
        ' If the original file was not a JPEG, append .JPG ext.
        If UCase(Right(SavePath, 3)) <> "JPG" Then
          SavePath = SavePath & ".jpg"
        End If
    
        jpeg.Save SavePath
    
    
    end if
    
    'Response.Write("Your image has been sucessfully uploaded. You can now close this window.")
    response.redirect "/admin/products/edit-image/?productpicture=" & File.ExtractFileName
    
    
    %>
    </body>
    </html>
    I got rid of the count as I am only ever uploading one file at a time.

    I changed the line

    Count = Upload.Save(Path) to FileName = Upload.SaveUnique(Path) but then when I open the file later with

    jpeg.Open( File.Path )

    I need to get the new file name (if indeed it was changed) instead of the old for when I resize it and save again.

    Also, how do I put the ID before the image before I upload it, then perform the SaveUnique to that.

    So timeline I guess I am trying to achieve

    - user selects image and presses submit (for example image is called foobar.jpg)
    - save page (script above) adds the id of the user uploading the image (33-foobar.jpg)
    - then when saving if 33-foobar.jpg exists then rename to 33-foobar1.jpg (this is the saveUnique bit)
    - reopen this file and resize
    - save the file again
    - redirect passing 33-foobar.jpg as querystring

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

    Default

    I think you have missed some tricks.

    1. If you do not provide the path to Upload.Save - then it will be saved in memory only and not on disk (and can be used exactly in the same way as you do now)

    2. Contstruct the name you want to save under using the file.Path, UID and File.Filename e.g.
    PathPrefix= Server.MapPath("/images/products/") & Session("UID") & "-"
    Path = PathPrefix & File.Filename

    Now you can resize it and then save it to disk for the first time using Jpeg.SaveUnique
    e.g. FileNameUsed=Jpeg.SaveUnique Path
    Path=PathPrefix & FilenameUsed

    3. response.redirect "/admin/products/edit-image/?productpicture=" & Path
    [You could also use a session variable to pass the path or better still merge the processing script and and the redirected page.

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

    Default

    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)

    Code:
    <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 >
    <%
    ' Create an instance of AspUpload object
    Set Upload = Server.CreateObject("Persits.Upload")
    
    Upload.ProgressID = Request.QueryString("PID")
    
    PathPrefix = Server.MapPath("/images/products/") & Request.Cookies("AdminId") & "-"
    'Path = PathPrefix & File.Filename
    
    FileNameUsed = Jpeg.SaveUnique(PathPrefix)
    Path=PathPrefix & FilenameUsed
    
    
    ' Obtain File object representing uploaded file
      Set File = Upload.Files(1)
    
      ' 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( File.Path )
    
    'onl resize if bigger
    if Jpeg.OriginalWidth > 600 then
    
    
    W = 600
    
    ' Resize, preserve aspect ratio
    Jpeg.Width = W
    Jpeg.Height = Jpeg.OriginalHeight * W / Jpeg.OriginalWidth
    
    end if
                    
                    
    
        SavePath = Path & "\" & File.ExtractFileName
    
        ' AspJpeg always generates thumbnails in JPEG format.
        ' If the original file was not a JPEG, append .JPG ext.
        If UCase(Right(SavePath, 3)) <> "JPG" Then
          SavePath = SavePath & ".jpg"
        End If
    
        jpeg.Save SavePath
    
    
    end if
    
    response.redirect "/admin/products/edit-image/?productpicture=" & Path
    
    
    %>
    </body>
    </html>
    The code above gives an Object required: '' error on the FileNameUsed = Jpeg.SaveUnique(PathPrefix) line.

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
  •