Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resizing remote images with asp.net

Status
Not open for further replies.

blackrabbit

IS-IT--Management
Aug 22, 2002
204
US
I have a web forum that I created with asp.net. part of the forum allows users to post the URL to an image file so that they can have a custom picture in an avatar or in thier signature or even put a picture in a post so other people can see it.

The problem is that sometimes the pictures they post URL's for are a little too big and distort my nice web page. Is there a way in asp.net to get the height and width of a remote image? I'd like to get the width and height of the URL image and then use the proportion to resize the image so it fits on my page.

The URL's to the pictures are stored in my datatbase so my asp.net code would get the URL to the picture, find out its width and hieght, resize it if needed and then write the html <img> tag with the new dimensions so it fits. Can this be done? I saw aomething done in older ASP that did this.
 
Hi,
you can resize the image then pass it in the response stream. Here is a snippet of code that we used to do just that

Code:
 Dim image As New Bitmap(100, 100)
                Dim fs As New IO.FileStream(Server.MapPath("Data") & "\" & "wordicon.gif", FileMode.Open, FileAccess.Read)
                image = image.FromStream(fs)
                image = image.GetThumbnailImage(100, 100, Nothing, Nothing)
                image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
                fs.Close()
                Response.Flush()


hope that helps it has been a while since i wrote this so it is a bit fuzzy

bassguy
 
Use HttpRequest with the image url and get the stream with HttpResponse. And then use the bassyguy's example.

[morning]
 
Thanks for that joulius thats the part that was fuzzy

Bassguy
 
I want to do something similar, but people are uploading the pictures to my site. How do I resize them and then save them to the server.
 
jjmendo, thanks for tip on holmok. I downloaded it and will try that out.

I looked into this months ago when I discovered .net does a lousy job of converting images to GIFs. I also ran into problems water marking correctly. I wanted a component that would take a jpg, bmp png or whatever and convert it to a GIF and does as good a job as Photoshop would. I finally found This is a com object but it works great and it is easy and cost only 100 bux which will worth the time.

I can easily upload any image and resize, watermark and save it correctly in other image formats. It is also considerably faster then using the .net image objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top