| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
Image Resize Part II - resize image on the fly
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:
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 />")
%>
--Edit: (11/10/2009) Fixed the attached ASP.NET code to save the thumbnail in JPEG (aka JPG) format, making it smaller in size and more standard. To save in other format, change this line in the .aspx file: Code:
wrapper.Save(strThumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg); to any of the following:
--Edit: (12/10/2009) Upgraded the code to support JPEG compression. To use this new feature, pass the desired compression level in the querystring, for example: Code:
http://localhost/ImageResizer.aspx?image=C:\Inetpub\wwwroot\Images\ house.jpg&thumb=C:\Inetpub\wwwroot\Images\house_thumb.jpg&width=500&height=-1&compression=90 The above will save the thumbnail with compression level (quality) of 90 which means good quality but rather large file size. good luck and happy programming! ![]() Last edited by Shadow Wizard : October 12th, 2009 at 08:49 AM. Reason: code upgrade |
|
#2
|
||||
|
||||
|
Yahav, I looooooooooooooooooove you.
Did I mention that I love you Yahav?
__________________
www.simplelyrics.net - www.playstormgames.com.com - www.g1games.com - www.quotemeanings.net - www.ourfreegames.com |
|
#3
|
|||||
|
|||||
|
** Disregard this...I just got it fixed! There was a permissions problem after all -- the internet guest account on this new server wasn't the default IUSR :\
I've combined your upload script with the resizer to create thumbnails of images when they are uploaded. The following script piece only uploads the original file and nothing more. I tested to see that paths are right...what am I doing wrong? ASP Code:
Last edited by baseballdude_ : October 4th, 2006 at 12:22 AM. |
|
#4
|
||||
|
||||
|
I actually am having the same problem again. The XMLHTTP doesn't seem to work right (even though it doesn't error) and doesn't create the thumbnail. I have this temporarily solved, having it create an iframe to be displayed, lol...but do you know what I'm doing wrong from the post above?
|
|
#5
|
||||
|
||||
|
debug the code by adding those lines:
Code:
Dim strURL, strResult
strURL = strPathToDir & "ImageResizer.aspx?image=" & strImageName & "&thumb=" & strThumbName & "&width=120&height=-1"
Response.Write("URL: " & strURL & "<br />")
objXML.Open "GET", strURL, True
objXML.Send
strResult = objXML.ResponseText
Respose.Write("response: " & strResult & "<br />")
and let me know the result of the debugging. |
|
#6
|
|||
|
|||
|
Does it support only JPG? Tried with GIF images and it didn't create thumbnail.
|
|
#7
|
||||
|
||||
|
it may fail on certain images. attach the image here if possible and
I'll see for myself. did you try successfully with other images? |
|
#8
|
|||
|
|||
|
Quote:
Try it yourself with any image other than JPG. It works perfectly with JPG, but I had no luck with GIF or PNG. |
|
#9
|
||||
|
||||
|
Quote:
can't use my code, sorry. |
|
#10
|
||||
|
||||
|
Quote:
come with something better, that at least will show error or message if something fails. |
|
#11
|
|||
|
|||
|
Quote:
Thanks! |
|
#12
|
|||
|
|||
|
This i just what i've been looking for! Is there any way of compressing the file size? When i resize an imge the file size is really big. When I resize an imgage which is 1024x768 (142kb) to 512x384 the file size is bigger then the original (397kb). ANy suggestions?
|
|
#13
|
||||
|
||||
|
Quote:
over the technical part of the process. I will try and search for alternatives though, will update this thread if and when I'm successful. ![]() |
|
#14
|
||||
|
||||
|
does this script really make the thumbnail file size bigger?
Shem
__________________
Everyone has a photographic memory. Some don't have film. I am a nobody, nobody is perfect, therefore I am perfect.
|
|
#15
|
||||
|
||||
|
Quote:
you'll have to test with some images and see for yourself. ![]() |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Image Resize Part II - resize image on the fly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|