#31
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0
    on my server it is working perfectly. the problem occured on my local machine
  2. #32
  3. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by ranegade
    on my server it is working perfectly. the problem occured on my local machine
    sorry, can't see why this happens. try with different XMLHTTP component maybe?
  4. #33
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2004
    Location
    NC, but moving out west in the near future
    Posts
    3
    Rep Power
    0
    I would like to start off with by saying
    GREAT CODE!!!

    OK.
    I have implemented you code into my Upload project
    But it only creates one image.

    Example
    The code for uploads, if the filename exist, then it add's a
    -# (# being 1 - 1000000 ) to the end of the image.

    I have added this to your script.

    Code:
    Dim strImageName, strThumbName, objXML
    strImageName = left(DestFileName, 255)
    strThumbName = "th_"&left(DestFileName, 255)
    Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
    objXML.Open "GET", "http://192.168.2.9/site/Projects/Images/ImageResizer.aspx?image=" & Server.MapPath(strImageName) & "&thumb=" & Server.MapPath(strThumbName) & "&width=144&height=218", True
    objXML.Send
    Set objXML=Nothing
    But it will only save the image as: th_image.jpg

    So, if I upload 5 images with the same name, it will not create the Thumbnail past the first image name
    So if I do
    image-1.jpg (The upload script names it with a -1 as a duplicate)
    Your script will not create another image

    The Database Insertion works great, for every Thumbnail that is created, The Actual Thumbnail is never created.

    Also. how can I put the generated thumbnail into a specific folder? Without know the full drive path?

    Could you please assist me on this issue?
    Thank you.
    Carrzkiss

    [QUOTE=Shadow Wizard]Attached is aspx file that can resize given image on the fly to the
    desired width and/or height.QUOTE]
  6. #34
  7. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    if the thumbnail is being saved with the same name, it means "DestFileName" has
    the same value.. I'll need to see more code to be able to help with this.

    regarding saving in specific folder, it's more simple than what you think:
    Code:
    objXML.Open "GET", "http://192.168.2.9/site/Projects/Images/ImageResizer.aspx?image=" & Server.MapPath(strImageName) & "&thumb=" & Server.MapPath("/thumbs/" & strThumbName) & "&width=144&height=218", True
    see the bold part for what you need to change.
  8. #35
  9. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0
    Hi!
    this code is just what i need and it works beautifully on my localhost but on server its giving me the following error. Can you please suggest what i should do?
    thanking you in advance.


    Error saving file: A generic error occurred in GDI+.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Exception: Error saving file: A generic error occurred in GDI+.

    Source Error:

    Line 237: catch (Exception exp)
    Line 238: {
    Line 239: throw new Exception("Error saving file: "+exp.Message);
    Line 240: }
    Line 241: }


    Source File: d:\inetpub\vhosts\india\httpdocs\aspnetuploader\Im ageResizer.aspx Line: 239

    Stack Trace:

    [Exception: Error saving file: A generic error occurred in GDI+.]
    ASP.BitmapWrapper.Save(String filename, ImageFormat fileFormat) in d:\inetpub\vhosts\india\httpdocs\aspnetuploader\Im ageResizer.aspx:239
    ASP.BitmapWrapper.Save(String filename) in d:\inetpub\vhosts\india\httpdocs\aspnetuploader\Im ageResizer.aspx:228
    ASP.aspnetuploader_imageresizer_aspx.Page_Load(Obj ect sender, EventArgs e) in d:\inetpub\vhosts\india\httpdocs\aspnetuploader\Im ageResizer.aspx:64
    System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +14
    System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +35
    System.Web.UI.Control.OnLoad(EventArgs e) +99
    System.Web.UI.Control.LoadRecursive() +50
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627




    Originally Posted by Shadow Wizard
    Attached is aspx file that can resize given image on the fly to the
    desired width and/or height.

    Credits for the code go to GunBlade who developed the core logic.

    To use the code and resize image, follow those steps:
    1. get server that support ASP.NET
    2. on that server, copy the aspx file as is.
    3. browse to the aspx file in such manner:
      Code:
      http://localhost/ImageResizer.aspx?image=[full image path here]&thumb=[full path of thumbnail to be created here]&width=[desired width]&height=[desired height]
    4. if you have desired width only and would like the height
      calculated automatically, then pass -1 as the height.
    5. if you have desired height only and would like the width
      calculated automatically, then pass -1 as the width.
    6. for example, suppose you got image called "house.jpg" in
      folder named "Images" and you want it resized to 500 pixels
      width:
      Code:
      http://localhost/ImageResizer.aspx?image=C:\Inetpub\wwwroot\Images\house.jpg&thumb=C:\Inetpub\wwwroot\Images\house_thumb.jpg&width=500&height=-1
      the above will save the thumbnail as house_thumb.jpg in the
      same folder.


    to use this in classic ASP code, use XMLHTTP component in
    order to "communicate" with the aspx file. simply pass the
    URL as demonstrated above:
    Code:
    <%
    Dim strImageName, strThumbName, objXML
    strImageName = "mypicture.jpg"
    strThumbName = "mypicture_thumb.jpg"
    Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
    objXML.Open "GET", "http://localhost/ImageResizer.aspx?image=" & Server.MapPath(strImageName) & "&thumb=" & Server.MapPath(strThumbName) & "&width=500&height=-1", True
    objXML.Send
    Set objXML=Nothing
    Response.Write("original: <img src=""" & strImageName & """ /><br />")
    Response.Write("thumbnail: <img src=""" & strThumbName & """ /><br />")
    %>

    good luck and happy programming!
  10. #36
  11. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    this is permissions problem.
    http://weblogs.asp.net/anasghanem/ar...exception.aspx
    grant ASPNET account full permissions over the folder you're trying
    to create the thumbnail in and it should work fine.
  12. #37
  13. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0
    Thankyou I got the code working
  14. #38
  15. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2004
    Posts
    12
    Rep Power
    0
    Hi!

    I am having some problem here. Please advised me.

    I had no problem with the codes on my own local machines. So prior the uploading to the server, i will have to change e URL. But however after that i had a problem. My image is uploaded but the image resizer never seemed to be executed. Please help!

    Basically while the files are resized it will be renamed as well. I need to execute Image Resizer twice to get 2 different sizes of the same image.

    Code:
    IF objUpload("file1") <> "" THEN  
    
    Call objUpload.File(0).SaveToDisk(Server.MapPath("productimages"), varFileName1)  
    
    strImageName = "\productimages\" & varFileName1 & ""
    strThumbName = "\productimages\stb_" & varFileName1 & "" 
    strDisplayName = "\productimages\sd_" & varFileName1 & "" 
    
    Set objXML = Server.CreateObject("Microsoft.XMLHTTP")  
    objXML.Open "GET", "http://www.abcefg.com/ImageResizer.aspx?image=" & Server.MapPath(strImageName) & "&thumb=" & Server.MapPath(strDisplayName) & "&width=328&height=-1", True 
    
    objXML.Send 
    Set objXML=Nothing  
    
    Set objXML = Server.CreateObject("Microsoft.XMLHTTP") 
    objXML.Open "GET", "http://www.abcefg.com/ImageResizer.aspx?image=" & Server.MapPath(strImageName) & "&thumb=" & Server.MapPath(strThumbName) & "&width=100&height=-1", True 
    
    objXML.Send 
    Set objXML=Nothing 
    
    END IF
  16. #39
  17. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2004
    Posts
    12
    Rep Power
    0
    Secondly i faced another problem too:

    I can execute these codes in IE7. However in Firefox, they said the image i upload is not an image.

    Can anyone please help? Thanks!!
  18. #40
  19. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by winterpolaris
    Secondly i faced another problem too:

    I can execute these codes in IE7. However in Firefox, they said the image i upload is not an image.

    Can anyone please help? Thanks!!
    glad it's working on IE7.
    what do you mean "they said the image i upload is not an image"?
    who said? sounds like it's not related to the image resize code..
  20. #41
  21. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Thumbs down Major Problem With Code


    shadwowizard, he is actually right! Its not JPG image file. Some image viewer cannot detect it as JPG if opened as JPG.
    --------------------------------------------------------

    I have found a major problem with this code. After resizing the image its mostly bigger than original. This increased my doubts about the image format itself. So I just tried to open new JPG image with IRFANVIEW Image Viewer, I was surprised to see that the JPG image was actually a PNG file. IRFANVIEW asked me to rename it to PNG as it detected it as PNG file. Then it opened it properly as PNG.

    Now the secret is revealed why the size was bigger. PNG is not a compressed format like intelligent compressed format like JPG.

    Now I came to know that the ASPX code is actually making PNG file and not the JPG though the extension we are asking it to make JPG.

    I am not into .NET, hence requresting the developer to make changes so it will not save JPG of 140kb into PNG of 400kb even after resizing to smaller size.

    I AM SURE THAT THE DRAWING NAMESPACE CAN HANDLE IT WELL TO MAKE A TRUE JPG IMAGE FILE, A COMMON PRACTICE IN INTERNET AUTHORING.

    Mahendra
    India
  22. #42
  23. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by indiacam
    shadwowizard, he is actually right! Its not JPG image file. Some image viewer cannot detect it as JPG if opened as JPG.
    --------------------------------------------------------

    I have found a major problem with this code. After resizing the image its mostly bigger than original. This increased my doubts about the image format itself. So I just tried to open new JPG image with IRFANVIEW Image Viewer, I was surprised to see that the JPG image was actually a PNG file. IRFANVIEW asked me to rename it to PNG as it detected it as PNG file. Then it opened it properly as PNG.

    Now the secret is revealed why the size was bigger. PNG is not a compressed format like intelligent compressed format like JPG.

    Now I came to know that the ASPX code is actually making PNG file and not the JPG though the extension we are asking it to make JPG.

    I am not into .NET, hence requresting the developer to make changes so it will not save JPG of 140kb into PNG of 400kb even after resizing to smaller size.

    I AM SURE THAT THE DRAWING NAMESPACE CAN HANDLE IT WELL TO MAKE A TRUE JPG IMAGE FILE, A COMMON PRACTICE IN INTERNET AUTHORING.

    Mahendra
    India
    thanks for the heads up, I'll take a look and try to see what's going on.
  24. #43
  25. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Proved to be one-line fix, I've uploaded the fix to my original post.
    Problem was that I have used the "Raw Format" of the image object
    itself, which is probably PNG for some reason.
    Now I'm "forcing" JPEG image format and it appears to work fine.
    Thanks again!
  26. #44
  27. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0
    Originally Posted by Shadow Wizard
    Proved to be one-line fix, I've uploaded the fix to my original post.
    Problem was that I have used the "Raw Format" of the image object
    itself, which is probably PNG for some reason.
    Now I'm "forcing" JPEG image format and it appears to work fine.
    Thanks again!
    Dear Shadow Wizard! Simply WOW and THANKS.

    One more Suggestion and Request! The quality and size of JPEG image required by us, can be controlled while saving by level of quality adjustment e.g. 50% to 100%. Is there any parameter you can set in aspx file so that we can pass a value to control the quality and size of file even more accurate. Example for thumbnails the quality of 50% is enough which makes size 2 to 3 kbs only. For bigger size quality is around 65 to 75. Image still more clear but file size is optimum. Just give it a try. Lets make this code unbeatable.

    ------------------

    Your reply was really so fast! I still wondor, how come no one noticed this problem in such a long duration of this code submission on 3rd October 2006?

    I feel great because I could give my bit to help you make this code outstanding. I will sure test it and post a feedback. Thanks a lot again.

    Mahendra
    Bhaarat (aka India)
  28. #45
  29. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by indiacam
    Dear Shadow Wizard! Simply WOW and THANKS.

    One more Suggestion and Request! The quality and size of JPEG image required by us, can be controlled while saving by level of quality adjustment e.g. 50% to 100%. Is there any parameter you can set in aspx file so that we can pass a value to control the quality and size of file even more accurate. Example for thumbnails the quality of 50% is enough which makes size 2 to 3 kbs only. For bigger size quality is around 65 to 75. Image still more clear but file size is optimum. Just give it a try. Lets make this code unbeatable.
    Your Wish Is My Command, see the original post I have uploaded
    new code that support different compression level for the thumbnail.
    To set desired compression, add "&compression=X" to the URL
    where X is the desired number.
    Let me know if you have problem with this.

    Originally Posted by indiacam
    Your reply was really so fast! I still wondor, how come no one noticed this problem in such a long duration of this code submission on 3rd October 2006?
    Good question.. probably this code is not really in wide use or
    people just didn't care/notice.

    Originally Posted by indiacam
    I feel great because I could give my bit to help you make this code outstanding. I will sure test it and post a feedback. Thanks a lot again.
    No problem Mahendra, hope you'll put my code into good use!

Similar Threads

  1. ShadowResizer - image resize on the fly (classic ASP)
    By Shadow Wizard in forum Code Bank
    Replies: 23
    Last Post: June 26th, 2011, 01:51 AM
  2. vb: image resizing from stream to SQL Server
    By timandkids in forum .NET Development
    Replies: 0
    Last Post: November 10th, 2004, 11:54 AM
  3. Howto resize with stretch and save an image in jpg format?
    By zwonimir in forum Visual Basic Programming
    Replies: 3
    Last Post: August 24th, 2004, 06:08 AM
  4. resize external image.
    By telnoi in forum .NET Development
    Replies: 2
    Last Post: July 27th, 2004, 04:40 PM
  5. Image Resize Problem
    By adathelad in forum .NET Development
    Replies: 0
    Last Post: February 4th, 2004, 04:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo