WordPress.org

Support

Retina displays

Viewing 3 replies - 1 through 3 (of 3 total)
  • Paul

    @come-back-home

    I figured that this wasn’t possible so I made a simple function out of solution 5 suggested on this blogpost:

    http://www.bdoran.co.uk/2012/08/28/detecting-and-delivering-images-to-retina-displays/

    function get_pixel_ratio() {
    
            $pixelRatio = 1;
            if (isset($_COOKIE["pixel_ratio"])) {
                $pixelRatio = $_COOKIE["pixel_ratio"];
            } else {
                ?>
                <script language="javascript">
                    writeCookie();
                    function writeCookie()
                    {
                        var pixelRatio = 1;
                        if (window.devicePixelRatio) {
                            pixelRatio = window.devicePixelRatio;
                        }
                        document.cookie = "pixel_ratio=" + pixelRatio + ";" + document.cookie;
                        location = '<?= $_SERVER['PHP_SELF'] ?>';
                    }
                </script>
    
            <?php
        }
    
        return $pixelRatio;
    }
    Paul

    @come-back-home

    Just for future reference, the above function did not work that well because in some cases it reloaded/redirected back to the front page if the cookie wasn’t set.

    I used a slightly modified technique presented on this blogpost:
    http://oxidedesign.com/detecting-a-retina-display/

    So here is the function I’m using now which seems to work fine:

    function get_pixel_ratio() {
    
          if ( isset( $_COOKIE['retina'] ) ) {
    
            $pixel_ratio = $_COOKIE['retina']; 
    
          } else { ?>
    
          <script type="text/javascript">
    
          var retina = 'retina='+ window.devicePixelRatio +';'+ retina;
    
          document.cookie = retina;
    
          if ( document.cookie.length !== 0 ) { document.location.reload(true); }
    
          </script>
    
          <?php } 
    
          return $pixel_ratio;
        }
    Plugin Author Mindshare Labs, Inc.

    @mindshare

    Detecting retina displays is not something we are planning on including with PHP Browser Detection at this time.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Retina displays’ is closed to new replies.
Skip to toolbar