I Now Display My Slideshow Images In Their Original Dimensions

I used to display my slideshow images all with the same dimensions.
This was to make sure that the images stayed in their alloted space on my homepage.
Unfortunately, this would change the aspect ratios of some images to an unacceptable degree.
I'm displaying all the images now with their original dimensions, so none of them get funny looking.
This blog is about how I did that, but it's also one of my ongoing blogs about how my homepage
gets me to look up how to do do web stuff (and use up my time).

I was just reading this blog and realized that first time visitors to my website might start reading blogs from the bottom up (latest first) and not know anything about my slideshow. I crawl the internet for images and write their URL to a file when I find them. When the file is written to, an AJAX script (look that up on the Internet if you don't know what that is) is alerted and reads the URL; the data parameter in an object tag (this works better for me then an img tag) is changed to the newly found URL value. This worked hassle free when I was using HTML 4, but with HTML 5 I found I needed to use an iFrame (something else you might want to look up). iFrames are basically windows in your web page to different web pages; i.e. the slideshow isn't coded into my homepage, but my homepage has a window to the page that does run the slideshow (this is seamless to the visitor). So the dimensions of the image are set in the page being displayed by the iFrame. OK, that's enough background information for this blog, so on to the original blog text:  

I display my slideshow in an iFrame. You can set the dimensions of the iFrame to whatever you'd like it to be, but that doesn't change anything on the webpage you're displaying in the iFrame (if that doesn't make sense to you, go ahead and look up iFrames on the Internet). The underlying webpage for the iFrame used to be NewGas.html, and the images were displayed using up 100% of the width and height of the webpage. This meant that I was probably changing the dimensions of the slideshow images, and hence their aspect ratios; i.e., the pictures were already funny looking before you saw them in the iFrame. So I needed to set the image dimensions in the underlying webpage. Changing the dimensions of the iFrame looked like it was having an effect on the image's aspect ratios, but I neeeded to fix the underlying problem; I was letting the image fill up the underlying webpage, causing it to look out of proportion.

I modified NewGas.html to display the images with their original dimensions, and renamed it NewerGas.html This means that some images will no longer fit in the alloted space for the slideshow. My workaround was to add a link to NewerGas.html that displays it in it's own page; my visitors can turn on a song and watch a slideshow in another window (or tab). Here's my html - for ScaledGas.html (note added 02/07/2016). My search program would come across some humongous image files, and they looked too funny - just a tiny part of the image would be viewable on my homepage. ScaledGas.html checks to see if the image file is wider then 557px (the widest image that will comforably display in my slideshow when viewed on my 1920px wide monitor) and scales it if it is that wide. This means I don't scale thumbnails (it would make them fuzzy looking) but humongous image files do get scaled. I probably should have checked for the width of the displaying document and scaled the image to be 29% as wide as that (the right side division is 29% as wide as my homepage is in total) but I'm worried that the visitor's JavaScript might not work the same way as the JavaScript on my system (I only trust assembly language) and he/she will see an image that is scaled funny. In any case, this reminds me that I really need to check for mobile devices and scale differently for those (next project - probably next weekend, as of this writing). BTW the link to see my slideshow full screen still goes to NewerGas.html.

New Note (02/08/2016). I now trust JavaScript. I was watching my slideshow while I was at work, on my cell phone; the pictures looked OK until you realized they were truncated. I replaced the constant 557 (see the paragraph above) with document.body.offsetWidth and my pictures scale the same in every browser:


<html>
 <head>
 <title>Classical Gas</title>
 <script language = "javascript">
    var handleCntr = 0;
    var SpockArr = [];
    var oldText = new String("http://community-info.org/DavePics/MB300SLR.jpg");
    SpockArr[0] = "http://community-info.org/DavePics/Spock/AlternateUniverse.jpg";
    SpockArr[1] = "http://community-info.org/DavePics/Spock/Cat.jpg";
    SpockArr[2] = "http://community-info.org/DavePics/Spock/Combat.jpg";
    SpockArr[3] = "http://community-info.org/DavePics/Spock/Disbelief.jpg";
    SpockArr[4] = "http://community-info.org/DavePics/Spock/Fascinating.jpg";
    SpockArr[5] = "http://community-info.org/DavePics/Spock/GirlFriend.jpg";
    SpockArr[6] = "http://community-info.org/DavePics/Spock/GuideToDating.jpg";
    SpockArr[7] = "http://community-info.org/DavePics/Spock/LiveLongAndProsper.jpg";
    SpockArr[8] = "http://community-info.org/DavePics/Spock/Logic.jpg";
    SpockArr[9] = "http://community-info.org/DavePics/Spock/MindMeld.jpg";
    SpockArr[10] = "http://community-info.org/DavePics/Spock/MovieSpock.jpg";
    SpockArr[11] = "http://community-info.org/DavePics/Spock/One.jpg";
    SpockArr[12] = "http://community-info.org/DavePics/Spock/Phaser.jpg";
    SpockArr[13] = "http://community-info.org/DavePics/Spock/Pilot.jpg";
    SpockArr[14] = "http://community-info.org/DavePics/Spock/RaisedEyebrow.jpg";
    SpockArr[15] = "http://community-info.org/DavePics/Spock/ArcherVulcanSaute.jpg";
    SpockArr[16] = "http://community-info.org/DavePics/Spock/SpockAndUhuru.jpg";
    SpockArr[17] = "http://community-info.org/DavePics/Spock/SpockInside.jpg";
    SpockArr[18] = "http://community-info.org/DavePics/Spock/SpockOnVulcan.jpg";
    SpockArr[19] = "http://community-info.org/DavePics/Spock/SpockOutside.jpg";
    SpockArr[20] = "http://community-info.org/DavePics/Spock/SpockRedBackground.jpg";
    SpockArr[21] = "http://community-info.org/DavePics/Spock/SpockShip.jpg";
    SpockArr[22] = "http://community-info.org/DavePics/Spock/StarWars.jpg";
    SpockArr[23] = "http://community-info.org/DavePics/Spock/Sunset.jpg";
    SpockArr[24] = "http://community-info.org/DavePics/Spock/T'Pol.jpg";
    SpockArr[25] = "http://community-info.org/DavePics/Spock/T'PolAndDoctor.jpg";
    SpockArr[26] = "http://community-info.org/DavePics/Spock/T'PolBaby.jpg";
    SpockArr[27] = "http://community-info.org/DavePics/Spock/T'PolBridge.jpg";
    SpockArr[28] = "http://community-info.org/DavePics/Spock/T'PolPhaser.jpg";
    SpockArr[29] = "http://community-info.org/DavePics/Spock/T'PolTrip.jpg";
    SpockArr[30] = "http://community-info.org/DavePics/Spock/Tricorder.jpg";
    SpockArr[31] = "http://community-info.org/DavePics/Spock/VulcanLegionOfHonor.jpg";
    SpockArr[32] = "http://community-info.org/DavePics/Spock/WhiteBackground.jpg";
    SpockArr[33] = "http://community-info.org/DavePics/Spock/Surak.jpg";
    SpockArr[34] = "http://community-info.org/DavePics/Spock/T'PolArmed.jpg";
    SpockArr[35] = "http://community-info.org/DavePics/Spock/T'PringAndSpock.jpg";
    SpockArr[36] = "http://community-info.org/DavePics/Spock/Selfie.jpg";

     // Used to detect whether the users browser is an mobile browser
        function isMobile()
        {           
            ///<summary>Detecting whether the browser is a mobile browser or desktop browser</summary>
            ///<returns>A boolean value indicating whether the browser is a mobile browser or not</returns>

            if (sessionStorage.desktop) // desktop storage
                return false;
            else if (localStorage.mobile) // mobile storage
            return true;

            // alternative
            mobile = ['iphone','ipad','android','blackberry','nokia','opera mini','windows mobile','windows phone','iemobile'];
            for (var i in mobile) if (navigator.userAgent.toLowerCase().indexOf(mobile[i].toLowerCase()) > 0) return true;

            // nothing found.. assume desktop
            return false;
        }
       
    function getDataReturnText(dataSource, callback)
    {
       var XMLHttpRequestObject = false;
            
       if (window.XMLHttpRequest)
       {
          XMLHttpRequestObject = new XMLHttpRequest();
       }
       else if (window.ActiveXObject)
       {
          XMLHttpRequestObject = new
          ActiveXObject("Microsoft.XMLHTTP");
       }

       if(XMLHttpRequestObject)
       {
          XMLHttpRequestObject.open("GET", dataSource);

          XMLHttpRequestObject.onreadystatechange = function()
                                              {
                                                 if (XMLHttpRequestObject.readyState == 4 &&
                                                     XMLHttpRequestObject.status == 200)
                                                 {
                                                    callback(XMLHttpRequestObject.responseText);
                                                 }
                                              }

          XMLHttpRequestObject.send(null);
       }
    }

    function callback(text)
    {
       var cntr = randomnumber=Math.floor(Math.random()*SpockArr.length);   
       if ((text.toLowerCase().indexOf("http") == -1) || (text.toLowerCase().indexOf("trans.gif") > -1))
       {
           text = "SpockArr[cntr]";
       }
       if (text.toLowerCase().indexOf('trans') > -1)
       {
          text = "http://community-info.org/DavePics/MB300SLR.jpg";
       }
      
       //write to the data file only if we have a new image
       if (text != oldText)
       {
          var img = new Image();

          img.onload = function()
         {
            var height = img.height;
            var width = img.width;
            var imgDivWidth = document.body.offsetWidth;           
            var moby = isMobile();
           
            if (moby)
            {
               imgDivWidth *= 0.87;
            }
           
            if (width == 0)
            {
               document.getElementById("imageObject").height = 540;
               document.getElementById("imageObject").width = 490;
               document.getElementById("imageObject").data = "http://community-info.org/DavePics/BettyPageBikini.jpg";
            }
            else if (width > imgDivWidth)
            {                                                      
               document.getElementById("imageObject").style.height = height * imgDivWidth/width;
               document.getElementById("imageObject").style.width = imgDivWidth;
               document.getElementById("imageObject").data = text;
            }
            else
            {
               document.getElementById("imageObject").height = height;
               document.getElementById("imageObject").width = width;
               document.getElementById("imageObject").data = text;
            }
            oldText = new String(text);                 
         }
         img.src = text;        
       }        
       setTimeout( "getDataReturnText('http://community-info.org/scripts/data.txt', callback);",10);              
    }
 </script>
 </head>

 <body onload="getDataReturnText('http://community-info.org/scripts/data.txt', callback)">              
    <div id="targetDiv">
        <OBJECT id="imageObject" data="http://community-info.org/DavePics/GirlOnGullwing.jpg" type="image/jpeg" style="width: auto; height: auto; max-height: 100%">          
           <img src="http://community-info.org/DavePics/512SProduction.jpg" alt="Ferrari 512S" style="width: auto; height: auto" />            
        </OBJECT> 
    </div>       
 </body>
</html>


  The Ferrari 512S image is what I display when the image in the slideshow is missing. I already know the 512S image is 798 px by 524 px, so I hard coded that, but the dimensions of every picture is discovered dynamically and the display dimensions are set to those values. BTW, I really needed to review my code. I set the conditions for certain images that I needed to replace with other images (e.g., if the image had the string 'trans' in it's name - probably a transparent gif, so I wouldn't want to "display" it, but display one of my own images), but I had messed up the condition of an image with zero size; it's fixed now.

Return To My Blog Page       Return To My Programming Page