Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Which approach is faster ? calculate Image size in Server or Client ?

Which approach is faster ? calculate Image size in Server or Client ?

Scheduled Pinned Locked Moved ASP.NET
csharphtmlasp-netgraphicssysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nadia Monalisa
    wrote on last edited by
    #1

    Hi, I learned that, if I use image height and image width attribute in html than, the page loads faster because the internet explorer wont need to calculate the image dimension. So, in my ASP.NET code behind file, I calculate the image from server and render html code with appropriate height and width attribute for image. Now, I am wondering, if I dont calculate the image height and image width in server and let the browser calculate it on the fly when rendering, will that be more efficient ? Here is my code that I used to get Image Size in Server:

    public static Size GetImageDimension(string absolutePath)
        {
            byte\[\] imageData = File.ReadAllBytes(absolutePath);
    
            var fullSizeImageHeight = -1;
            var fullSizeImageWidth = -1;
            MemoryStream origStream = null;
            System.Drawing.Image fullSizeImg;
            try
            {
                origStream = new MemoryStream(imageData);
                fullSizeImg = System.Drawing.Image.FromStream(origStream);
                fullSizeImageHeight = fullSizeImg.Height;
                fullSizeImageWidth = fullSizeImg.Width;
            }
            catch
            {
            }
            finally
            {
                if (origStream != null)
                    origStream.Dispose();
            }
    
            return new Size(fullSizeImageWidth, fullSizeImageHeight);
        }
    
    V 1 Reply Last reply
    0
    • N Nadia Monalisa

      Hi, I learned that, if I use image height and image width attribute in html than, the page loads faster because the internet explorer wont need to calculate the image dimension. So, in my ASP.NET code behind file, I calculate the image from server and render html code with appropriate height and width attribute for image. Now, I am wondering, if I dont calculate the image height and image width in server and let the browser calculate it on the fly when rendering, will that be more efficient ? Here is my code that I used to get Image Size in Server:

      public static Size GetImageDimension(string absolutePath)
          {
              byte\[\] imageData = File.ReadAllBytes(absolutePath);
      
              var fullSizeImageHeight = -1;
              var fullSizeImageWidth = -1;
              MemoryStream origStream = null;
              System.Drawing.Image fullSizeImg;
              try
              {
                  origStream = new MemoryStream(imageData);
                  fullSizeImg = System.Drawing.Image.FromStream(origStream);
                  fullSizeImageHeight = fullSizeImg.Height;
                  fullSizeImageWidth = fullSizeImg.Width;
              }
              catch
              {
              }
              finally
              {
                  if (origStream != null)
                      origStream.Dispose();
              }
      
              return new Size(fullSizeImageWidth, fullSizeImageHeight);
          }
      
      V Offline
      V Offline
      vaghelabhavesh
      wrote on last edited by
      #2

      In my opinion, calculating the image dimensions on server side means doing I/O operations for each image request, so its better we ask individual client (i.e. browser) to do that. In that case your web server will not have that much load but yeah the browser may take some more seconds.

      If you are not criticized, you may not be doing much. 'Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.' Robert Heinlein (1907 - 1988)

      N 1 Reply Last reply
      0
      • V vaghelabhavesh

        In my opinion, calculating the image dimensions on server side means doing I/O operations for each image request, so its better we ask individual client (i.e. browser) to do that. In that case your web server will not have that much load but yeah the browser may take some more seconds.

        If you are not criticized, you may not be doing much. 'Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.' Robert Heinlein (1907 - 1988)

        N Offline
        N Offline
        Nadia Monalisa
        wrote on last edited by
        #3

        Hi, Thanks for your reply. Actually I am concerned about the overall speed, So, let assume that, the time taken in server for FILE IO operation and image size calculation is = Ts And the time taken in client for image size calculation on the fly is = Tc, I need to know, if Ts > Tc or Ts < Tc. If Ts < Tc, I will use server side code to calculate image size, I dont care about server load as the page I am rendering is a protetected page, only one user can see that page. If Tc < Ts, then, I will let the browser calculate and display the page. So, can you please tell me which value is higher ? Ts or Tc ? It is very hard to experiment and find out these values, so I thought if this information is already known by others, it would be helpful. Regards.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups