quarta-feira, 16 de julho de 2014

Deliver High-Res Images on Mobile Devices with RetinaJS

High-resolution screens on mobile inclination is now a norm. The images give users a crook and crispier look, and once they have gotten used to this high spin quality, web developers are pulpy to furnish high-quality imagery for their users as well. Most images that we use a decade ago will really spin becloud on a retina arrangement screen, so we need a new approach to benefaction graphics on a Web.


The ways we can adopt change depending on a purpose of a image. Font Icon and SVG is now a improved approach to offer icons or logo, while Media Queries is a approach to offer picture from CSS.


But if we wish to offer hi-res picture within a physique content, Retina.js is a approach to go. Retina.js, a JavaScript library that creates portion high-resolution images a breeze. You don’t even have to cgange most of your code. Let’s check it out.



Getting Started


Retina.js does not rest on any arrange of third-party libraries. All we need is to download a retina.js record and couple it in your document. Alternately, we can couple a record from CDNJS.com, like so.



script src="//cdnjs.cloudflare.com/ajax/libs/retina.js/1.0.1/retina.js"/script

Retina.js offers two methods to offer high-resolution images.


Method 1


In a initial release, Retina.js adopts a same routine as Apple did in a devices, that attaches a hi-resolution picture with @2x suffix. So if we have an picture named autumn.jpg, we name a high-res chronicle as autumn@2x.jpg. In chronicle 1.3.0, Retina.js introduces a new suffix, _2x. So aside from @2x we can name a picture as autumn_2x.jpg.


Retina.js will check your server for images with these suffixes when your website is noticed on a high-resolution screen, and will reinstate a unchanging picture with it. To safeguard Retina.js picks adult a picture successfully, we have to save a high-resolution picture in a same office where your unchanging chronicle is saved.


Method 2


Another approach is by regulating a data-at2x within a img tag, like so.



img src="img/autumn.jpg" data-at2x="img-hi-res/image-autumn.jpg" alt=""

By regulating this data- charge we can set a name of a folder or a picture differently, and Retina.js will not perform a server check; this will speed adult a process.


Open your website in a apart screen; one in unchanging shade and another in high-resolution. Compare them, and we should see a disproportion (like below).



LESS Mixins


Retina.js also provides a LESS Mixins, .at2x, to offer picture by CSS. This example:



.social-icons
.at2x('image/icons.jpg');


…will spin into a following when gathered into unchanging CSS.



.social-icons
background-image: url('image/icons.jpg');

@media (-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)
.social-icons
background-image: url("image/icons@2x.jpg");
background-size: automobile auto;



Quite handy, right?


Using Retina.js In WordPress


WordPress users can use a plugin called WP Retina 2x to implement Retina.js in their website. Assuming that we have commissioned a plugin and also uploaded images, we can go to Media WP Retina 2x menu. You should see a list of images that we have uploaded, as follows.



Click a Generate button. It will beget images with @2x appendix for Thumbnail, Medium, Large, and a other tradition picture sizes that we have specified.



Final Thought


Seeing a augmenting series of inclination with high resolutions, it is usually a matter of time before web developers can't equivocate ancillary it. Retina.js is a all-in-one library to offer high-resolution images. You can use images with the@2x or data-* charge within your physique content, use .at2x Mixins for portion your website picture by CSS, and there is a plugin accessible for WordPress.





<!–



Suggestion:





–>




You competence like:









Advertisement





Deliver High-Res Images on Mobile Devices with RetinaJS

Nenhum comentário:

Postar um comentário