Image
  • Home
  • About
  • Contact
  • Portfolio

Updating For Retina

26 Feb
Filed Under: Web Development

I spent some time recently upgrading the graphics on my photog­raphy site, Bob Rockefeller Photography. Some of it was pretty easy, some of it just needed a little code tweak to go with paired images (one at normal reso­lution, the other at high), and some of it took a little more work. Here’s what I did.

The favicon was the least trouble. I figured there was no need to do all the work John Gruber explained to make two different reso­lu­tions of the favicon to be served to normal and retina displays. So I just created the favicon at 32 x 32, in PNG format, and served that to all comers. Well… not to Internet Explorer visitors. IE doesn’t do PNG, so I put an old 16 x 16 ICO format favicon in the web site’s root directory for it. For everyone else, I called for the 32 x 32 favicon like this:

XHTML
1
<link href="wp-content/uploads/favicon.png" rel="icon">

Why do we still have to jump through hoops for Internet Explorer? Never mind…

If you’d like the WordPress dash­board to use that favicon, too, add this to your theme’s functions.php file:

PHP
1
2
3
4
5
// ! Specify favicon for Dashboard
function favicon4admin() {
   echo "   <link href="path/to/favicon.png" rel="icon" />"
}
add_action( 'admin_head', 'favicon4admin' );

You can get more details from the article Understand the Favicon.

Next up was the site logo and that was pretty straight-forward. I went back to the source file (Abobe Illustrator) and saved it in SVG instead of PNG format. A little HTML work and that was done.

accordianThe accordion slider on the home page required a little more work, but after a couple of attempts that turned out to be dead ends, it wasn’t too bad. The root of the solution was to add the retina.js script to my site. This little gem checks your <img> tags for image files that look like image.jpg and swaps them out for ones that look like image@2x.jpg.

Create double reso­lution images for all your standard reso­lution files and save them in the same place with the now-common image@2x.jpg naming convention and the script takes over from there. The bonus is that this JavaScript takes care of ALL my images, even the ones in my port­folio galleries. For extra ease, add the WP Retina 2x plug-in and it will create all the right assets auto­mat­i­cally when you add media to your site. Done.

lightboxLast up was handling images loaded into a lightbox for viewing larger; the thumb­nails were taken care of with retina.js. I was using Lightbox Evolution which was perfect for what I wanted before, but when I attempted to contact the author to see if he was planning to make changes to accom­modate retina displays, I got no reply. A little detective work lead me to ColorBox.

At first ColorBox didn’t use low reso­lution images for regular displays and high-resolution images for retina displays. But a posting on the ColorBox GitHub page and a couple of emails exchanged with the author, Jack Moore, and it does now!

I could have just used the JavaScript directly, but instead chose to have the WordPress plug-in jQuery Lightbox For Native Galleries handle loading and config­u­ration. The plug-in has been discon­tinued in favor of features in JetPack, but it still works just fine. I do my devel­opment locally and JetPack does not work well in that envi­ronment. The only trick was that the plug-in comes with an older version of ColorBox, so I had to update that manually.

To get thinks working just as I wanted, I made a small change to jquery-lightbox-for-native-galleries.php so the JavaScript constructed looks like this:

1
2
3
4
5
6
7
8
9
10
jQuery(document).ready(function($){
   $(".gallery").each(function(index, obj){
      var galleryid = Math.floor(Math.random()*10000);
      $(obj).find("a").colorbox({rel:galleryid, transition:"elastic",
        opacity:0.65, retinaUrl:true, retinaImage:true, scrolling:false,
        maxWidth:"810px", maxHeight:"830px"});
   });
   $("a.brp_lightbox").colorbox({transition:"none", opacity:0.65, retinaUrl:true,
     retinaImage:true, scrolling:false, maxWidth:"810px", maxHeight:"830px"});
});

That finished the work. All my images, in every size, are shown as normal reso­lution for normal displays and high-resolution for retina-class displays.

Comments

  1. Jordy Meow says:
    March 4, 2013 at 3:08 AM

    Thanks a lot for mentioning my plugin WP Retina 2x :)

    Reply
    • Bob Rockefeller says:
      March 4, 2013 at 4:48 AM

      Thank you for the plug-in. It works well.

      Bob

      Reply

Leave a Reply

Click here to cancel reply.

Who Is Bob Rockefeller?

I’m a pho­tog­ra­pher and a Macintosh user who shoots what catches my eye and tries to remember David duChemin’s credo: “Gear is Good. Vision is Better.” I also dabble in HTML, CSS and WordPress coding. [Read More …]

My Other Sites

  • Bob Rockefeller Photography
  • My 500px Portfolio
  • My Facebook Page
  • My Pixoto Page

Blogging Shooters

  • David duChemin
  • David Hobby
  • Derrick Story
  • Joe McNally
  • John Thawley
  • Martin Bailey
  • Robert Boyer
  • Scott Kelby

Links To Good Gear

  • Apple
  • B&H
  • FlashZebra
  • Other World Computing

Popular Posts

  • Some Custom Squarespace CSS Code
  • Finding A Photo Sales Site
  • Sublime Text 2 Is Really Good
  • PocketWizard vs. RadioPopper For Canon eTTL
  • Using Google Web Font Variants

Categories

  • Admin
  • Aperture
  • Business
  • Lightroom
  • Macintosh
  • Opinion
  • Photography
  • Printing
  • Translating Lightroom
  • Web Development

Copyright © 2008–2013 Bob Rockefeller • Custom theme on the Builder Framework by iThemes • WordPress • Log in