Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2922

    Post ShadowResizer - image resize on the fly (classic ASP)


    note: newer version is available in this thread. I'm leaving this
    thread to serve as different approach to the same issue.


    Attached is little C# command line application which can resize
    pictures using smart resize.
    Using the application requires .NET framework 1.1 or later to be
    installed on the computer.
    The application can be used with classic ASP too, with the
    WScript.Shell component - note that for this to work, you should
    have .NET framework installed on the server, plus permissions to
    execute command line applications.
    No installation is required - just copy the file to the same location
    as your ASP file and see the attached sample code for example
    of using it. sample picture is given as well.
    Sample code is below as well:
    Code:
    --TestResize.asp
    <% Option Explicit %>
    <%
    '-----------------------------------------
    'constants
    Const RESIZER_FILE_NAME="ShadowResizer.exe"
    Const ORIGINAL_IMAGE_NAME="sample_picture.jpg"
    Const THUMB_IMAGE_NAME="sample_picture_thumb.jpg"
    '-----------------------------------------
    
    '-----------------------------------------
    'methods
    Sub Resize()
    	Dim objShell, strCommand
    	Set objShell = Server.CreateObject("WScript.Shell")
    	strCommand = Server.MapPath(RESIZER_FILE_NAME) & " " & Server.MapPath(ORIGINAL_IMAGE_NAME)
    	If IsNumeric(Request("width")) Then
    		strCommand = strCommand & " -width=" & Request("width")
    	End If
    	If IsNumeric(Request("height")) Then
    		strCommand = strCommand & " -height=" & Request("height")
    	End If
    	strCommand = strCommand & " -saveas=" & Server.MapPath(THUMB_IMAGE_NAME)
    	objShell.Run strCommand, 0, True
    	Set objShell=Nothing
    End Sub
    '-----------------------------------------
    
    '-----------------------------------------
    'main
    If Request("action")="1" Then
    	Call Resize()
    End If
    '-----------------------------------------
    %>
    <html>
    <head>
    <title>Shadow Resizer Example</title>
    </head>
    <body>
    Original image: <img src="<%=ORIGINAL_IMAGE_NAME%>" /><br />
    <% If Request("action")="1" Then %>
    New image: <img src="<%=THUMB_IMAGE_NAME%>" /><br />
    <% End If %>
    <form action="<%=Request.ServerVariables("Script_Name")%>">
    <input type="hidden" name="action" value="1" />
    Width: <input type="text" name="width" value="<%=Request("width")%>" />(empty to smart resize by height)<br />
    Height: <input type="text" name="height" value="<%=Request("height")%>" />(empty to smart resize by width)<br />
    <button type="submit">Resize</button>
    </form>
    </body>
    </html>
    as you can see, the sample page take picture and let you decide
    its new height and/or width - the resulting picture is true
    thumbnail with new dimensions.

    Comments on this post

    • MARKEDAGAIN agrees : thx shadow
    Attached Files
    Last edited by Shadow Wizard; February 4th, 2007 at 02:23 AM.
  2. #2
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Apr 2006
    Posts
    1
    Rep Power
    0

    Exclamation Thanks, but need help!


    Hi Shadow, thanks for the great code. I seem to recieve an error from the exe file. I have it installed on my locall IIS machine, and I think I have execute rights on the folder it is in. Maybe I have granted incorrect permissions?

    Here is the error, it occurs after I enter demension and I cick resize:
    Application has generated an exception that could not be handled.
    Process id=0x678 (1656), Thread id=0x15cc (5580).

    Any ideas on what the problem could be? I do have .Net Framework installed on my machine.

    Thanks
  4. #3
  5. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2922
    sounds like you don't have the .NET framework, or maybe you have old version.
    if you do have the new version, try executing the application from the command line:
    Start --> Run --> Cmd --> cd C:\Inetpub\wwwroot --> ShadowResizer.exe ...
    and hopefully more meaningful error message will appear in the console.
  6. #4
  7. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2005
    Posts
    154
    Rep Power
    10
    its very good.

    but can it do like in windows Thumbnails function?

    i means is in My Pictures Folder Function.

    somethings like this

    before
    [img]
    http://img.photobucket.com/albums/v430/Chen/new.gif
    [/img]

    after
    [img]
    http://img.photobucket.com/albums/v430/Chen/newthumd.gif
    [/img]
    Thanks.
  8. #5
  9. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2922
    no idea what you mean, sorry.
  10. #6
  11. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2005
    Posts
    154
    Rep Power
    10
    i mean is

    before the image is like this
    maybe this image is 190X20

    after i thumbnail the image it will become like this

    it become 128X128

    that mean is after i resize the image it not lose shape.
    hope you understand my question

    thanks
  12. #7
  13. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2922
    if you force both width and height, it would "lose shape". nothing can fix that.
    this image you posted is the same image, only in the second you put white
    background around it. I have no clue what you did by that.
  14. #8
  15. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2005
    Posts
    154
    Rep Power
    10
    i also dun know how the Windows XP do it

  16. #9
  17. Expert Learner
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Feb 2005
    Location
    Wisconsin
    Posts
    1,909
    Rep Power
    97
    That's not the acutal image. The entire square is a placeholder, with an image inside it.
  18. #10
  19. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2005
    Posts
    154
    Rep Power
    10
    Originally Posted by baseballdude_
    That's not the acutal image. The entire square is a placeholder, with an image inside it.
    Yes, i want the thing like this
  20. #11
  21. Expert Learner
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Feb 2005
    Location
    Wisconsin
    Posts
    1,909
    Rep Power
    97
    Then just place a box around the image.
  22. #12
  23. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2005
    Posts
    154
    Rep Power
    10
    Originally Posted by baseballdude_
    Then just place a box around the image.
    yes i know.

    problem is how i resize the image and not lose the shape?

    Thanks
  24. #13
  25. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2922
    sorry chen, my program only resize the image. it's not meant for image preview.
    if you give it only width or height, it will perform "smart resize" and the
    image will not lose shape. I can't explain any better, hope you can
    understand.
  26. #14
  27. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2005
    Posts
    154
    Rep Power
    10
    Originally Posted by Shadow Wizard
    sorry chen, my program only resize the image. it's not meant for image preview.
    if you give it only width or height, it will perform "smart resize" and the
    image will not lose shape. I can't explain any better, hope you can
    understand.
    Ok never mind.

    because i have ask many people before how it do it.
    but poor is not one can answer me.

    And Thanks your code.

    Thanks Shadow Wizard and baseballdude_
  28. #15
  29. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2922
    no problem chen, sorry I can't help any further!
Page 1 of 2 12 Last
  • Jump to page:

Similar Threads

  1. javascript to resize background image to suit all screen reasalutions
    By sk8ter04 in forum HTML, JavaScript And CSS Help
    Replies: 4
    Last Post: November 6th, 2007, 03:21 AM
  2. vb: image resizing from stream to SQL Server
    By timandkids in forum .NET Development
    Replies: 0
    Last Post: November 10th, 2004, 12:54 PM
  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, 07:08 AM
  4. resize external image.
    By telnoi in forum .NET Development
    Replies: 2
    Last Post: July 27th, 2004, 05:40 PM
  5. Image Resize Problem
    By adathelad in forum .NET Development
    Replies: 0
    Last Post: February 4th, 2004, 05:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo