Hacker News new | past | comments | ask | show | jobs | submit login
Adaptive Images in HTML (adaptive-images.com)
35 points by orofino on April 21, 2012 | hide | past | favorite | 21 comments



Urrggghhh, PHP?

But this is exactly the kind of thing that PHP is good at. Dump a file in a directory that does one specific thing, and you're good to go. No need to integrate it with the rest of your web site. It's just a little CGI-like script that does its own thing.

But if you use this on a smallish VPS, keep an eye on memory usage. Image processing in PHP tends to hog a lot of RAM, and even a small number of simultaneous requests can crash a server. You might need to warm your cache a little bit before going public with new images.


If you read up on the it, you'll see that this creates the images on the fly and you can specify a time for it to cache them. You don't have to be constantly recreating the images.


That's why I said you might want to "warm your cache" before making new images public.


I'm not terribly well versed with nginx, but the creator mentions only support for .htaccess, I was able to get this working with the following in my config for nginx:

  if ($request_filename !~* ai-cache) { 
   rewrite \.(?:jpe?g|gif|png)$ /adaptive-images.php last; 
  }


All of these adaptive image solutions are heroic but incredible hacks. They load two images, load no images when JavaScript is disabled, depend on userAgent sniffing, and/or only work with specific backend technologies.

What we need is the ability to tell the client what we have, then let the client choose the right one based on screen size and bandwidth. Browsers should be able to do that for us. Here's one solution along that line:

http://www.alistapart.com/articles/responsive-images-how-the...


You should actually read the details page before criticizing the project. It does none of the things you say. In fact the technique is very similar to the one detailed in the ALA article.


Yes, it says the requirements are Apache 2, PHP 5.x, and GD lib. I would call those specific server-side technologies.


But it doesn't "load two images, load no images when JavaScript is disabled, depend on userAgent sniffing". The only reason PHP or GD is needed is to automatically generate alternate image sizes, which the ALA author does manually.


"load no images when JavaScript is disabled"

This solution works fine if JavaScript is disabled. It just loads the smallest image if "mobile" is in the user agent string and the largest image otherwise.

http://adaptive-images.com/details.htm


Yeah, and this "solution" does false advertising. For crap's sake, it's not a HTML solution if I need JavaScript, Apache and (ffs) PHP.


Isn't this something solved by CSS media selectors? Choose the images via CSS ("background" images, appropriately sized) within media selector criteria such as resolution and density.

As an aside I despise any separation that even brings up the word mobile. My smartphone has a higher resolution than many desktops...coupled with a higher network performance than many high speed connections. The days of treating these mobile computers as gimpy halfwits is long past.


With background images you lose the ability to scale an image to fit its container, which is one of the key components of a truly adaptive (fluid) layout. However, if you are using a fixed grid that merely resizes at certain thresholds in viewport width (like bootstrap's adaptive grids), that will work fine.

Regarding mobile, I'm not sure the separation is about performance as much as it is about being nice to users with capped data plans. And even with a high resolution mobile display, you just don't need the same size images for a 3 inch phone as you do for a 24 inch desktop monitor. In fact, I think one of the intentions of the responsive design movement is to serve identical experiences to desktops and mobiles, while adjusting the format somewhat to make the latter easier on the eyes. This is a huge improvement over serving one of those dumbed-down, text only mobile sites that blogs and such are so fond of redirecting you to (I'm looking at you, wordpress).


CSS property background-size (https://developer.mozilla.org/en/CSS/background-size) has contain and cover properties, which will scale the image to fit its container.


Yes, I'm looking forward to dropping IE8 support so I can use this. :)


How would you use CSS media selectors with dynamic content?


the CSS could be created on the fly, outside of a unified stylesheet.


This approach was also put forward by Stephanie Rieger. Specifics start at slide #83:

http://www.slideshare.net/yiibu/adaptation-why-responsive-de...


Also have a look at the discussion reg. server-side vs client-side adaptive images hacks at:

http://24ways.org/2011/adaptive-images-for-responsive-design...


That lowercase /t/ in their choice for the body font is really annoying.


this is cool:)


Just in time for 4G to be everywhere in my area :/ Where were you 3 years ago? Now I would just be annoyed by this when I tried to zoom in on an image and got a pixellated mess.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: