Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

Convert "ASP.NET" -to- ASP

Hello All;

   Could someone convert this from ASP.NET -over-to- ASP?
Thank you.
Carrzkiss

======================================================================
<%@ Page Language="C#" %>
<%@ import Namespace="System.IO" %>
<script runat="server">

    // This function return the tag string to resize an image at the desired MaxWidth and MaxHeight, maintaining the image Height/Width Ratio
    string COMMONFUNCTIONS_IMAGES_RESIZE_TO_TAG(System.Drawing.Image img, int MaxWidth, int MaxHeight)
        {
            if (img.Width > MaxWidth || img.Height > MaxHeight)
            {
                double widthRatio = (double) img.Width / (double) MaxWidth;
                double heightRatio = (double) img.Height / (double) MaxHeight;
                double ratio = Math.Max(widthRatio, heightRatio);
                int newWidth = (int) (img.Width / ratio);
                int newHeight = (int) (img.Height / ratio);
                return " width=\"" + newWidth.ToString() + "\"" + " height=\"" + newHeight.ToString() + "\" ";
            }
            else
            {
                return "";
            }
        }


        private void LoadImage()
        {
            // sets the name of the image
            string imageUrl = "emanuelebriano.gif";
            // gets width and height
            int Img_Width = Int32.Parse(txtWidth.Value);
            int Img_Height = Int32.Parse(txtHeight.Value);

            // gets the image width and height tag
            string s_ImageSize = " width=\"0\" height=\"0\" ";
            if (File.Exists(Server.MapPath(imageUrl)))
            {
               System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(imageUrl));
               s_ImageSize = COMMONFUNCTIONS_IMAGES_RESIZE_TO_TAG(img, Img_Width, Img_Height);
            }

            // draw the image
            divImage.InnerHtml = "<img src=\"" + imageUrl + "\" border='1' " + s_ImageSize  + " />";
            divDim.InnerHtml = s_ImageSize;
        }

        void Button1_Click(object sender, EventArgs e) {
            LoadImage();
        }

</script>

<!-- Code by Emanuele Briano --- http://www.emanuelebriano.it -->

<html>
<head>
</head>
<body>
    <form runat="server">
        <div id="divImage" runat="server">Image will be loaded here
        </div>
        <div id="divDim" runat="server">
        </div>
        <br />
        <br />
        <br />
        <br />
        <div>maxWidth:
            <input id="txtWidth" type="text" value="300" runat="server" />&nbsp;&nbsp;&nbsp;&nbsp;
            maxHeight:
            <input id="txtHeight" type="text" value="100" runat="server" />
        </div>
        <div>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Load"></asp:Button>
        </div>
        <div>&nbsp;
        </div>
        <div>Code by <a href="http://www.emanuelebriano.it">Emanuele Briano</a>
        </div>
    </form>
</body>
</html>

======================================================================
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

There is no direct conversion for the image manipulation part, you will need to find (or write your own) COM component to manipulate the image.
Avatar of Wayne Barron

ASKER

well, I cannot write my own. (Am not that good)
So I will do some checking, to see if there are any "Free" ones, or maybe a decent priced Paid one.

Thanks Carl.
If you know of any, please let me know.
As for some strange reason the following code:

<img src="<%=adoRecords.Fields("Thumbnail")%>"
onload="if (this.width>97) this.width=97; if (this.height>54) this.height=54;"></a>

Will work in a simple small page.
But will not work in the actual LIVE page.

Sort of strange really. I really do not know "why" it is not working in the actual page.
And why it will only work in a smaller-cut down page??

Thanks a bunch.
try to use the onLoad even within  Body tag like this

<head>
function widthtest() {
if(document.images["abc"].width>97) {
  document.images["abc"].width=97
} else if(document.images["abc"].width>54){
document.images["abc"].width = 54
}
</head>

<body onLoad="widthtest">

<img src="<%=adoRecords.Fields("Thumbnail")%>"
 name="abc"></a>
adilkhan
Thank you for your reply.

Within the Brackets you have:    ["abc"]

What exactly is this standing for? Hopefully, it is not the ImageName itself.

And it would be more like this in the code:

function widthtest() {
if(document.images["abc"].width>97) {
  document.images["abc"].width=97
} else if(document.images["abc"].height>54){
document.images["abc"].height = 54
}

You had all "Width" and forgot to add in the "Height".
Just thought I would correct it for you :)
, But, please let me know about the   ["abc"] and what it is?
you are right, abc is the Image name.
Humm, that could be a problem.
The Images are random.

Something like this:

<img src="<%=adoRecords.Fields("Thumbnail")%>"
 name="<%=adoRecords.Fields("PName")%>"></a>

There is over 40,000+ items located in the Database.
And at one time or another, all the images will be loaded within the page.
(Not all at ones, of course, 8-Images are loaded each time, depending on
There Popularity. (There Hits))

How would that work with this code?
OK.
Testing out the code. (Forget my last comment, lost my thought for a moment)

This code goes between the

<head>
function widthtest() {
if(document.images["abc"].width>97) {
  document.images["abc"].width=97
} else if(document.images["abc"].height>54){
document.images["abc"].height = 54
}
</head>

It cannot be added as such.
It needs to be Wrapped in something.

This is a Function, is it a Javascript Function?

I wrapped it like so:

<script type="text/javascript">
function widthtest() {
if(document.images["MiniImages"].width>97) {
  document.images["MiniImages"].width=97
} else if(document.images["MiniImages"].height>54){
document.images["MiniImages"].height = 54
}
</script>

--------
Made this tag
<img src="<%=adoRecords.Fields("Thumbnail")%>" name="MiniImages">
------------

I get this error:        'widthtest' is underfined.
<body onLoad="widthtest">
---------------

Could you please assist on getting this working? As right now, it is not working
Most likely, due to the Error shown above.

Thanks adilkhan;
adilkhan
Once you get an operatunity to look into my last comment, and we can find a solution.
I will award you the points.
Trying to clean up all my open questions.

Thanks
Wayne
I figured out what it needed to be wrapped with:

<script language="JavaScript">
<!--
function widthtest() {
if(document.images["MiniImages"].width>97) {
  document.images["MiniImages"].width=97
} else if(document.images["MiniImages"].height>54){
document.images["MiniImages"].height = 54
}
//-->
</script>

But, I am still receiving the same error:

'widthtest' is underfined.
<body onLoad="widthtest">

I am trying myself to figure this out, but if you get the chance, I could really use your input.

Thanks.
<body onLoad="widthtest()">

you missed () with your function name.
<body onLoad="writetest()" >

Gives me the error:  Object Expected

------
Do I have the Function in the correct place?

Also, I have this in the <Body> as well, do not know if it would cause a problem or not.
But here is my Whole <body> tag


<body onLoad="writetest()" "MM_preloadImages('images/b2r.jpg','images/b3r.jpg','images/b4r.jpg','images/b5r.jpg','temp-images/b2r.jpg','temp-images/b3r.jpg','temp-images/b4r.jpg','temp-images/b5r.jpg')">

Of which the:   MM_preloadImages   <-- is also a: onLoad
Sorry for the TYPO <body onLoad="writetest()" >
Correct that issue, <body onLoad="widthtest()" >

But it is still giving me the same Error as I have listed above:  Object Expected

<body onLoad="widthtest();MM_preloadImages('images/b2r.jpg','images/b3r.jpg','images/b4r.jpg','images/b5r.jpg','temp-images/b2r.jpg','temp-images/b3r.jpg','temp-images/b4r.jpg','temp-images/b5r.jpg')">

if you want to call multiple Functions with one event then seperate them with a ;
still giving me the same error. Object Expected

Here is all the code how I have it.
======================================
<head>
<script language="JavaScript">
function widthtest() {
if(document.images["MiniImages"].width>97) {
  document.images["MiniImages"].width=97
} else if(document.images["MiniImages"].height>54){
document.images["MiniImages"].height = 54
}
//-->
</script>
</head>
<!--The onLoad="widthtest(); <-- Give Error [Object Expected]-->
<body onLoad="widthtest();MM_preloadImages('images/b2r.jpg','images/b3r.jpg','images/b4r.jpg','images/b5r.jpg','temp-images/b2r.jpg','temp-images/b3r.jpg','temp-images/b4r.jpg','temp-images/b5r.jpg')">

<img src="<%=adoRecords.Fields("Thumbnail")%>" name="MiniImages">
======================================
Your Function is missing a closing curly brave "}"


<script language="JavaScript">
function widthtest() {
if(document.images["MiniImages"].width>97) {
  document.images["MiniImages"].width=970
} else if(document.images["MiniImages"].height>54){
document.images["MiniImages"].height = 54
}
 }  
//-->
</script>
Well,
That cleared up the Error.
----------
The images are still displayed as there normal size.
And now one of the other features I implemented in the site, is not working.
(I will deal with it later)
But the images are still not working with this code either.
-----
Is there anything that you can think of that might be conflicting
In the way the code is suppose to be working?
can you put the width Attribute for testing into your images and see if it works or not..

<img src="test.gif" width=100 name="MiniImages">
I did this:

<img src="<%=adoRecords.Fields("Thumbnail")%>" width="75" name="MiniImages" >

And it set the image PERFECT.
Why? How come adding in the "width" into the tag, made it work? confused.
the Code is fine, i  just tested it and it works without having any Width/Height Attribute on my end.
So your ASP Variable does returns Correct image? when you view the properties of that image it shows correct Attributes?
This is what shows when I [View Partial Source] (I am so glad that IE5 Tools work with IE6)
------------------------------------------------------------------------------------------------
<A onmouseover="this.parentNode.className='Product'"
onmouseout="this.parentNode.className='Product ProductClosed'"
href="content_by_cat3.asp?contentid=652&amp;catid=111" target=_self><IMG
src="http://www.website.com/ProdImages/secret2.gif" width=75
name=MiniImages></A>
------------------------------------------------------------------------------------------------
Which the strange thing is that it is now not displaying the other code.
Which is the "onmouseover" event.
So now I have to find out why? your code interfers with existing code.
(What a mess, in order to have 1 thing to work, you sometimes have to sacrafice
Something else)
but i think we were calling that Function on <Body onLoad event> no the onmouseover event.
Correct.
Your Function is called through the <Body onLoad>
The other is from here: (Example of what suppose to happen, that is now not happening)
Just run your mouse over the image

http://www.carrz-fox-fire.com/c/Hints/hints.asp

Now, the code for the image Width Height. Is this:
<img src="http://www.website.com/images/products/SmMelipal.jpg"
onload="if (this.width>97) this.width=97; if (this.height>54) this.height=54;">

Though this code works flawlessly in this Demo page, it does not work in my actual page.
Thus the reason for your code here.

Your code <Here> works great (as long as I have the Width="65" or whatever added to the Tag)
But now the "onmouseover" Event does not fire now?

Now this is a Demo I just made up using Your code <Here>
http://www.carrz-fox-fire.com/c/Hints/adilkhan/hints.asp

As you can see the images are all there Original sizes.
And this is without putting in the         Width="65" name="MiniImages"
The only thing that is in the <img> tag is:    name="MiniImages"

Anyway,
I wanted to you to both of the demo pages.
One with the onmouseover working, with another person's code for Image resizing.
And then your code for Image Resizing, with the onmouseover not working.

Take Care
Wayne


Thanks for creating a directory with my user id(sure it makes me feel good heheheh).

in my version fo code you missing alot of code.

you missing the following..

<script type="text/javascript">

  var maxWidth = 123;
  var maxHeight = 82;

</script>
<style type="text/css">

body {
  color: black;
  background: silver;
}

table {
  border: 1px solid red;
}

div {
  border: 1px solid blue;
  padding: 1em;
}

td {
  vertical-align: top;
}

div.Product {
  padding: 1em;
}

div.Product div.Hint {
  position: absolute;
}

div.ProductClosed div.Hint {
  display: none;
}
</style>

Plese also make sure if you missing something else.
The code above it for the other "Image Resizing"
In your code <here> is replacing the above with:
=========================================
<script language="JavaScript">
function widthtest() {
if(document.images["MiniImages"].width>97) {
  document.images["MiniImages"].width=97
} else if(document.images["MiniImages"].height>54){
document.images["MiniImages"].height = 54
}
}
//-->
</script>
=========================================
since your code does not use none of the Functions from the other routine.
I simply just replaced it with only your Function here.

Hope that makes since?

-------
I figured you would like your UID being in the URL.
Besides, it easily shows you which one that you are viewing.
And it also shows you the Respect that I have gained for your assistance.

Thanks
:p

OK. You was right, I removed tooooo much code.
OK.
In the Demo page, your <code> is not working.
But the onmouseover is working.
http://www.carrz-fox-fire.com/c/Hints/adilkhan/hints.asp
so hold on a sec. you want image width/height to fix itself upon Page Load on when you place your cursor on Image?

I am sure you want it on Page Load. All the images have same names so obviouly Script will not work properly. we have to give each image a unique name and then Loop through them and do the width/height Test.

meanwhile have a string ready with all the image names like this.

Images = "Image1,Image2,Image3"

and within the Image Tag make sure each image has names like this.
<image name="image1">
<image name="image2">
If you looked at the 1st Demo page:
http://www.carrz-fox-fire.com/c/Hints/hints.asp
You will see that the images are a Fixed Size.
When you run the Mouse over the Image   onmousemove.
It will display a Properties Windows for the Product.

The images are already sized.
---------------
So lets not worry about that right now.
-----------------

Where would this need to be added at?

Images = "Image1,Image2,Image3"
thats because if we going to have multiple images then each image must have a unique name, then later in javaScript we will reference to each image with its correct height and width (using its unique name).

But you should really Resize Images in Photoshop instead or so, and have them properly dimensioned.
Where would this need to be added to in the code?
==============================
Images = "Image1,Image2,Image3"
==============================
Also.
I do not have access directly to the Images.
So I am unable to resize them to the dimensions that I would need them to be for the site.
So, until I can have access to the images, I will have to work with them this way.
Hello [adilkhan];
If you could please let me know where this will go:
==============================
Images = "Image1,Image2,Image3"
==============================
And if everything goes well and works, we can close this question out.

Please get back to me when you can, hopefully soon.

Take Care
Wayne
if you already have the images sized nicely then you dont have to do what i suggested above.

Reason why i mentioned that so we can give all t he images a unique name.

if you create a string like this "image1,image2"

Then with javaScript/Asp we will give each image that unique name

<img src="" name="image1">
<img src  ="" name="image2">

This in Body onLoad event we can resize all the images dynamiclly.

But since you resized all the images manually you no need to worry about it.
adilkhan;

  I think that you are not understanding me correctly.

I "Do Not" have access to the Images on my Server. They are being feed from another Server.
They are of Different "Sizes" and that is the reason why I need this "Event" that you are referring too.

Can you "Please" tell me where and in what area I would need to put the
String:                      image1,image2,image3

This is all that is needed to finish up this part of the site.
And "hopefully" everything else will fall into place.

So please, let me know where to add it at.

As right now, all I have is just the "onLoad" Event.

Thank you

ok, then lets do the Following Technique.

I am sure you are Looping through the Recordset to get all the Images from DB, Right?

when you generate your Image tag in ASP page lets do the Following..

Dim i
i = 0
<img src="someImg.src" name="MyImg" & <%=i%>> >
i = i + 1

so I assumed there are images coming out of database and they all will be having a unique name in the Sequence of..
MyImg0
MyImg1

and so on...

once you have this Ready post your HTML Code and i will write you javaScript Function.
The images are "Image links = their_site.com/images/something.jpg"
Names will have to be given to them through code not in the Database.

So it will be comething like this.

Dim i
i = 0
<img src="<%=adoRecords.Fields("Thumbnail")%>" name="MiniImage1"& <%=i%>>
i = i +1

And then each image will have a different name here.

MiniImage1,MiniImage2,MiniImage3,MiniImage4,MiniImage5 exc...
--------------------
With all the information that has been provided here, I beleive that you have enough
To do what you need to do.
But if not, then let me know and I will try to provide more information.

----------Please keep in mind----------------
I DO NOT have access to the Image physically. I only have "URL Links" to the images.
They are not being feed from my Server, but from their indivisual companies Servers.
So all the images have to be "Named" Through code above.
And Resized through code as well.
-------------------------------------------------

Thank you.
I have to reinstall my Laptop.
Been doing so much hard processing work on it the last week that it has
Corrupted my Win2k OS.

I will be checking in on my Other Main Computer to see what you have.

Wayne
ok i am writing the Function right now.
ASKER CERTIFIED SOLUTION
Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks adilkhan
I will test it out in a few.
I still have to complete the rest of the program installations on the laptop first.
Then I will jump on this one.
Probably later on this evening or in the morning.

Wayne
Code works great!!!!!!!!!!! FINALLY!!!!! :)
;;;;
For anyone that wants to use the code in there own pages. Some corrections to "adilkhan" code.
Line 12 in the <javascript> code. The size was incorrect [width=197  changed to  width=97]

In the <img> tag. you do not need to have the "width" inserted, it works without it.
If you have any problems, then try it with the Width="97" or what ever.
==================================================================
<script language="JavaScript">

function widthtest() {

imgs = document.images.length

 for(i=0; i<imgs; i++) {

   if(document.images["MiniImage"+i]) {

     if(document.images["MiniImage"+i].width>97) {
            document.images["MiniImage"+i].width=97
     }      else if(document.images["MiniImage"+i].height>54){
          document.images["MiniImage"+i].height = 54
     }
    }
 
 }

}
//-->
</script>

<body onLoad="widthtest()">
<img src="dsd.gif" width=50 name="MiniImage0">
<img src="dsd.gif" width="101" name="MiniImage1">
<img src="dsd.gif" width=100 name="MiniImage2">
<img src="dsd.gif" width=100 name="some OtheR Image">
<img src="dsd.gif" width=100 name="someOthdfdfeRImage">
==================================================================

Thank you adilkhan
I know it has taken about 4-5 days to finally get our stuff together to get it working.
And I thank you very much for sticking in here with me to get it to working properly.

The only thing I have to do now, is to figure out "why" the "Hints" window is not showing.
But that is different then this, so I am going to Award the points to your working code.
And then try to fix my problem and finally release this site by tomorrow.

Take Care [adilkhan]
Wayne
no problem Wayne, its my pleasure.
I am glad it finally worked for you.

I will keep an eye on you if i have a windows 2000 Question hehehe:)
:)
I love Win2k, Delphi, ASP.
I know more about my computer then I do of the others.
But...
Delphi (Windows programming)
I can make some beautiful Interface programs, and I have a great imagination for
What I want something to look like.

ASP
I can take someone else's scripts. Tear them apart and make what I need out of them
And sometimes make them better then they were originally.

I have been using
Win2k  - since 3 months after it was released. So I have learned a lot about the OS.
WinXP - I am writing a book on it, as it is too late to do one for Win2k.
And if I do not hurry up with the WinXP one, It will be too late for it, once "Vista" is released in 2007.

Delphi - been using it since about 2001
ASP - since around 2001-2002.

(Yea, I know, I should be able to do what ever I want with either one of them by now,
But unfortunantly, my mind, just does not want to remember everything that I have
learned, so if I do not have it written down somewhere, and cannot find my examples.
I have to rely on other's to assist me in my issues, like this one here.)

Thank you once again, and have a great evening.

By, the way.
Where are you located? (From)
I live in "NC USA"

Take Care
Wayne
yes you are right, you must release your book ASAP, its time for vista.

I work on Windows 2000 Active Directory (but i will not say i am a Active Directory Expert), I always wanted to Master Windows DNS and WINS and never really got good help on it.

but i am a master of Web Applications:)

I just finished a web application at khanZone.com, i am willing to sell it on online via google Adwords, but dont know how will it work.

I am from "NY USA" :)

Take Care
 Adil
I am getting ready to install Win2k Server, sometime within the next week.
I am going to use it for SQL Server 2k.

Active Directory, I tried to learn it with Win2k3 Server Enterprise.
It was a pain in the butt.
Even though I found a lot of great information from here. I finally had to go back
To my old faithful WinNT4 Server as my DC.
Until I have the time and not worry of Money, so that I can really learn it.
It is going to be a while before I deal with Active Directory.

DNS. I run my own DNS servers here.
They seem to run pretty good, have been doing my own DNS now for about 5yrs.
Can I teach someone? Only what I know, which is not very much,
But I can get a DNS Server up and running.

----------
You are just right up from me.
I was thinking maybe you was from another country :)
Of which a lot of EE users are.

Take Care Adil.

Wayne