Tuesday, February 26, 2013

Way to get Height and Width of image

Following code is used to get the height and width of image

//In case of images stored in sever.
System.Drawing.
Image objImage = System.Drawing.Image.FromFile(@"D:\a.jpg");


int width = objImage.Width;


int height = objImage.Height;

//In case of validating image before uploadbyte[] imgdata = System.IO.File.ReadAllBytes(@"D:\a.jpg");

System.IO.
MemoryStream memoryStream = new System.IO.MemoryStream(imgdata);

System.Drawing.
Image objStreemImage = System.Drawing.Image.FromStream(memoryStream);


int widthMemoryStream = objStreemImage.Width;


int heightMemoryStream = objStreemImage.Height;


Thanks
Mahesh

Wednesday, February 20, 2013

Run code ready or load of DOM

<script type="text/javascript">
      $(window).load(function () {
     //Do action after load
      });
   </script>

<script type="text/javascript">
      $(document).ready(function () {
     //Do action after document is ready
      });
   </script>

Thanks
Mahesh K Sharma

Sunday, February 17, 2013

How to increase/decrease font size to occupy complete width


<SCRIPT type=text/javascript>
        String.prototype.GetNumericFontValue = function () {
            return Number(this.replace('px', '').replace('pt', '').replace(/\s/g, ''));// removing px, pt, any type used in css and spaces
        };
        $(document).ready(function () {
            var standardTextWidth = 470;
            standardTextWidth = standardTextWidth - 20; /*we are taking 20 px less accuracy due different width of chars like i, W, l , M,j, etc*/
            var isExcecuted = false;
            $('.textContainer').each(function (index) {
                isExcecuted = false;
                var currentFontSize = String($(this).css('font-size')).GetNumericFontValue();
                /*Increase the font size to occupy available width*/
                for (currentFontSize; $(this).width() < standardTextWidth; currentFontSize = currentFontSize + 1) {
                    $(this).css('font-size', currentFontSize + 'px');
                    isExcecuted = true;
                }
                /*Decrease the font size to occupy available width*/
                if (!isExcecuted) {
                    for (currentFontSize; $(this).width() > standardTextWidth; currentFontSize = currentFontSize - 1) {
                        $(this).css('font-size', currentFontSize + 'px');
                    }
                }
            });

        });
        /*
        How to use:
        Need to change the selecter " $('.textContainer')" as per DOM and standardTextWidth default width of title.

        Limitation of above function:
        1. Width will increase or decrease in proportions of characters in string.
        2. Width of each char is different.
        */
    </SCRIPT>