Saturday, March 31, 2012

Setting Maximum Image Size

Hi,

This is my first post to ASP.NET.

I am new to .NET and have taken over a website developed by another company.

I have a requirement to change the width of an image on a product details page to 400pixels IF it is greater than 400pixels. If it is less than 400 pixels, then leave it as it is.

Here is what I have tried:

The HTML code:
------------------------------
<td id="LIC" valign="top" runat="server"
<asp:Label id="LImage" runat="server" visible="false" text='<%# DataBinder.Eval(Container.DataItem, "Image_Left") %>' ></asp:Label
<img id="Image_Left" runat="server" align="top" src='<%# DataBinder.Eval(Container.DataItem, "Image_Left", "images/{0}") %>' /
</td
The C# code:
------------------------------
if (((Label)details.Items[0].FindControl("LImage")).Text == "")
{
(details.Items[0].FindControl("LIC")).Visible=false;
(details.Items[0].FindControl("Image_Left")).Visible=false;
}
else
{
Response.Write("Found LEFT image: ");
Response.Write(((HtmlImage)details.Items[0].FindControl("Image_Left")).Width);
Response.Write(", ");
Response.Write(((HtmlImage)details.Items[0].FindControl("Image_Left")).Height);
}

I tried using the Response.Write method to debug and found that it returns -1 for both the width and height of the image.

I could really use some help here. Have tried all different combinations to no avail.

Thanks in advance!Hi,
Read :
True Image Resizing

Displaying a List of Scaled Images

HTH
Thanks! That really helped.

I now have another problem.

I want to be able to load images from another website and resize them if they are greater than 400 pixels wide. I cannot seem to figure out how to get the images from a URL.

Currently, my code looks like:

Dim imageUrl as String = Request.QueryString("img")

'Add on the appropriate directory
imageUrl = "/images/" & imageUrl

Dim currentImg as System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))

Dim imgWidth as Integer = currentImg.Width
Dim imgHeight as Integer = currentImg.Height

The above code works great if the images directory is on the same server. I want to be able to laod my images to a central server and then access those images (and resize them if needed) from other websites on other servers.

Any ideas?

Thanks in advance!
I have not been able to find anything to solve my problem. I need to know how to access and manipulate images on another server as I stated previously.

I cannot seem to find anything that does not use Server.MapPath.

Can anyone provide any guidance?

Thanks in advance!
Yeah.. Server.MapPath returns the true directory of a virtual path supplied, so its not what you want.

Do you have access to this remote server? I mean, you could do a web-request for the images in question, if you know the file names etc.. or you could request the image list, via a web-request, and use some Regex to get a list of all the images.. then simply request the images, and resize them, and save them to your server.

Is that what you are looking to do?
Basically, the idea is to have one web site be a repository of all the images that will be shared by other websites. We have one SQL server that currently only two sites are accessing to retrieve and display info from. The SQL server contains the names of the images that need to be diplayed by the sites so they both have access to the file names.

So I need to be able to request the image from site A and display on site B. The question is how do I get the image size and then resize before displaying if needed?

I hope that is clearer.
Hi,

Take a look @.GalleryNET FREE control

HTH

0 comments:

Post a Comment