Resize Images by Screen Resolution

Fixes relating to our templates are posted here.

Resize Images by Screen Resolution

Postby Helter » Mon Nov 07, 2005 11:48 pm

here is a tip I found on Austin's forum (maker of Amod)

As we all know, someone on 800x600 sees your site different from someone on a smaller resolution. For those who want to change that, here ya go.

Open page_header.php & at the top find

Code: Select all
  1. define('HEADER_INC', TRUE);


after that add

Code: Select all
  1.   if (isset($HTTP_COOKIE_VARS['users_resolution']))
  2.       $res = $HTTP_COOKIE_VARS['users_resolution'];


then find


Code: Select all
  1. $template->assign_vars(array(
  2.    'SITENAME' => $board_config['sitename'],


after that add

Code: Select all
  1. 'HEADER_IMAGE_WIDTH'   => (($res == '800x600') ? '400' : '480'),


close & save it.

Then open overall_header.tpl for any header you want to modify, find

Code: Select all
  1. </head>


before that add

Code: Select all
  1. <script type="text/javascript">
  2. <!--
  3. writeCookie();
  4.  
  5. function writeCookie()
  6. {
  7.  var today = new Date();
  8.  var the_date = new Date("December 31, 2023");
  9.  var the_cookie_date = the_date.toGMTString();
  10.  var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
  11.  var the_cookie = the_cookie + ";expires=" + the_cookie_date;
  12.  document.cookie=the_cookie
  13. }
  14. //-->
  15. </script>


And now everytime someone comes to your site, it will set a cookie with their screen resolution. This way you can determine how to size it. As you see we size it in page_header.php

Code: Select all
  1. 'HEADER_IMAGE_WIDTH'   => (($res == '800x600') ? '400' : '480'),


There. If they are on a 800x600 we make the image width a bit smaller (400) and if they are not on 800x600 we make it a bit bigger (actual size of 480)

Now to use it, whatever image you want to auto-size needs

Code: Select all
  1. width="{HEADER_IMAGE_WIDTH}"


Added to the image tag.

User avatar
Helter
Site Admin
 
Posts: 548
Joined: Tue Jul 19, 2005 1:29 pm
Location: Seattle Wa
Blog: View Blog (0)
Real Name: John Wagner


Post a reply



Return to Template Fixes

Who is online

Users browsing this forum: No registered users and 1 guest

cron