views:

441

answers:

4

Hi Stackers,

Problem Basicly, it's impossible to use a full-size photograph with the background-image in a proper way imo. Different resolutions, wide-screen etc etc. What im looking for is a JS/PHP GD solution for this problem.

Technique From what i hear, it would be as follows. Javascript looks up available screensize (browser window) or screenresolution. Parses this to PHP GD. On the FTP you'll have a high-res image (1600x1200 for example). The PHP GD scales this according to the information parsed by JS. This will also have to work onResize.

Since im 'just' a simple designer, my lack of JS/PHP is killing me over this issue.

If anyone can help me out with a proper solution, i would love to friend-link them on my new site once it's finished. Thanks in advance and much love from Holland.

Phil

+3  A: 

Basicly, it's impossible to use the background-image in a proper way imo.

I know that's your opinion but the rest of the web appears to disagree with you. They make it work. But that's probably not the major issue here.

Resizing a background for every user, hell, every request if you don't cache, is going to nuke your server in a nanosecond. GD resizes are expensive and if this is on shared hosting, you'll end up having your site kicked off it. If there are other sites on the same server, they'll slow to a crawl.

Even if you can shovel enough coal into the server, it's going to make for a pretty dodgy user experience. Rather than just being able to download the file, the browser is going to have to wait while the PHP generates the image and only then can it download.

And what if I loaded this site on a large screen? I've got a possible ~3840*1200 resolution here. Even if you don't scale it up, I'll have to download the full version. A large screen size doesn't mean I have redundant optical fibres to my computer.

But, all that said, it's certainly possible. I'd recommend you start with jQuery. It makes hooking onto window -load and -resize events and changing the CSS dynamically pretty simple. The gritty details can be accomplished with a few simple googles: "php resize image", "jquery onresize" and "jquery change background".

Oli
A: 

Hi Oli,

Thanks for your reply. Once i read your reply to the quote i thought: "Darn, i shouldve said fullsize background-images." Ofc you can always make an images wich fades into your background-color and such.

On the issue; Since it's a personal website, I cba with the (likely-les then) 1% with resolution higher then 1600x1200. I did find your information about the server-drainage very intresting. I had no experience with this.

I'll continue my search on Google wich hasnt been so successful thus far. Hence why im here. Thanks again on your reply tho. Take care.

Phil

Phil
Don't post non-answers as answers.
Sinan Ünür
A: 

You also can make several css style sheet to match some resolutions. this UNTESTED example may give you some help.

<html>
  <head>
    <title></title>
    <link rel="stylesheet" id="styleSwitch" href="" />

    <script  type="text/javascript">
      function getStyle(){
      var theStyleLink = document.getElementById('styleSwitch');­

     if (window.innerWidth < 810){
        theStyleLink.setAttribute("href", ­ "small-window.css");

     }
     else {
       theStyleLink.setAttribute("href", ­ "large-window.css");

       }
     }
   </script>
 </head>
 <body onload="getStyle();">

 </body>
</html>
Luis Melgratti
A: 

Hi Luis, Thanks for your reply. I have tried the multiple CSS file. It works to some limit. Yes, it pics the 'closest' correct file. But (there's always a big hairy but it seems), CSS never managed to tackle the 4:3 or widescreen difference. Plus i believe it'll pull the image out of its proportions when it comes to a widescreen.

Regar, Phil

Phil