Retina Monitor’s Web Image Solution

什麼是Retina螢幕


今天來談談網頁圖片在視網膜(Retina)螢幕的顯示議題,首先必須來談談什麼是視網膜螢幕,其實他就是一種能在單位尺寸內顯示更多像素點的螢幕,且已經達到視網膜能辨識的極限,視網膜螢幕是由蘋果公司提出,賈伯斯在2010年iPhone 4的發表會中提到:「當你所拿的東西距離你10-12英寸(約25-30厘米)時,它的解析度只要達到300ppi這個『神奇數字』(每英寸300個像素點)以上,你的視網膜就無法分辨出像素點了。」

所以簡言之,視網膜螢幕比較一般非視網膜螢幕的不同處在於,能在同樣的範圍顯示更多的像素點,也就是PPI(Pixels Per Inch)比較高的螢幕,可參考下圖所示:

可以看到圖左在單位尺寸內顯示的像素點較少,圖右則能以更多的像素去呈現,在肉眼上就會覺得圖右會比較細緻。

接下來談談網頁圖片與視網膜螢幕之間的關係,先來看看同樣一張圖片在不同螢幕上顯示的效果。

非Retina顯示

Retina顯示

當然在美觀的立場下,我們不會希望發生這樣的視覺差異,那網頁上要如何設置才可以做到讓圖形在視網膜螢幕下也能正常的顯示呢?以下提出一些解決方案:

方案1. 透過CSS針對不同的DPR (Device Pixel Ratio)設計顯示圖片


大家如果想知道自己螢幕的DPR,可以在Chrome的主控台輸入“window.devicePixelRatio”,就可以得知目前Chrome所在螢幕的DPR值。

非Retina螢幕
Retina螢幕

可以觀察出來在兩個螢幕的DRP值是不同的,而透過CSS的樣式,可以針對這兩個不同的DPR設定顯示方式,可以參考下面的做法:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .logo{
            width: 190px;
            height: 190px;
            background-image: url("atd-icon.jpg");
            background-size: contain;
        }
        @media (-webkit-min-device-pixel-ratio: 2){
            .logo{
                background-image: url("atd-icon@2x.jpg");
            }
        }
    </style>
</head>
<body>
    <div class="logo"></div>
</body>
</html>
<script>
</script>

這邊必須針對圖檔尺寸做個說明,其中atd-icon.jpg為190 x 190,而atd-icon@2x.jpg為380 x 380。

@media (-webkit-min-device-pixel-ratio: 2)的部分是在DPR兩倍下的Media Query。

透過這樣的方式去設定,當DPR為2的時候,螢幕上的圖片改變為atd-icon_2.jpg,剛好能夠滿足在兩倍像素狀況下的顯示需求,當然以此類推,也能去設定三倍或更高倍數下的顯示圖片。

方案二. 透過img標籤的srcset屬性


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img src="atdIcon.jpg" srcset="atd-icon@2x.jpg x2">
</body>
</html>
<script>
</script>

其中srcset=”atd-icon@2x.jpg 2x”表示在DPR等於2的時候要去呈現的圖片。

非Retina螢幕
Retina螢幕

以上兩個方法都可以解決圖片在Retina螢幕上面顯示的問題,但也要稍微注意一下支援程度:

CSS -webkit-min-device-pixel-ratio 支援列表
HTML srcset 支援列表

可以看到在IE都是無法支援的狀態,但從Edge後就開始支援,當然也可以想想目前擁有Retina螢幕的使用者,用的瀏覽器都會是哪些?說不定你不會太在乎上面那兩張圖紅色的部分。

但若是一定要有IE瀏覽器的支援,大家應該也能從上述的文章了解,我們可以透過window.devicePixelRatio的數值自行寫script進行判斷,然後再給出適合DPR的圖片,不過這邊另外推薦一個JS Library可以協助你進行這方面的判斷。

方案三. 透過Retina.js輔助進行判斷


首先到Retina.js的網站下載他們所提供的js檔,接下來至網頁引入該JS,其實網站上也有詳細的使用方法,另外檔案大小僅有約4KB並不算很大,可以參考下面的Sample Code。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="retina.min.js"></script>
</head>
<body>
    <img src="atd-icon.jpg" />
</body>
</html>

可以看到在img標籤中僅使用了原始大小的atd-icon.jpg,但因為有引入retina.min.js,他會在螢幕DPR兩倍時,自動去搜尋符合倍率下的圖片,但要記得如果不加其他屬性去設定兩倍圖片的檔名,檔名就必須按照內建的規則,也就是atd-icon@2x.jpg,當然3x也依然支援,可以到官網看一下他的使用方式,但若是使用CSS設定的背景,依然沒辦法透過retina.js達到支援IE的效果。

以上三個方法提供目前在設計網頁時,對於Retina螢幕支援的做法,若在不考慮IE瀏覽器的情況下,其實方法1+方法2就已經可以解決所有情況,但若要支援IE則可以參考方法三的做法,也歡迎大家有問題可以留言進行討論。

方案四. 使用SVG圖檔


過往我們在網頁中使用的圖片僅有GIF、PNG、JPG這三種點陣圖格式,所以在高解析度(Retina)的螢幕中,我們需要輸入不同Size的圖片,來補足像素點不足的問題,現在有了另外一種解法“SVG”圖檔。

大家可以把SVG視為一種可以放在網頁上的向量圖檔,也就是說我們以前透過Illustrator或其他向量繪圖軟體(也包含Photoshop中向量工具)繪製出來的向量圖,本身放大就不會失真,但因為要放在網頁上,我們把它轉換成了前述的三種點陣格式,才導致圖檔放大後的失真,而SVG就是保留圖片原來的向量屬性,簡言之,就是把向量圖檔放在網頁上的意思。

非Retina螢幕
Retina螢幕

感覺這個解決方案應該會比前幾項方便,但也有他必須要注意的地方:

  1. 在SVG檔案中匯入的點陣圖,在儲存成SVG時並不會被向量化,例如上圖中間的ASUS Design Logo就是匯入的點陣圖(放大後還是會模糊)。
  2. SVG字型可能會遺失,所以需要使用網路字型或是將文字轉成外框或形狀之後再轉存成SVG。
字型遺失
轉換成外框或形狀

You may also like...

7,928 Responses

  1. umnufzyj表示:

    buy modafinil oral modafinil 200mg order provigil 200mg

  2. DouglasLep表示:

    stromectol pills for humans stromectol for humans for sale stromectol for humans for sale

  3. Yzmgtx表示:

    ampicillin usa – order cipro for sale cialis online buy

  4. mgadnmhl表示:

    provigil 200mg over the counter modafinil 100mg pill cheap modafinil 100mg

  5. DouglasLep表示:

    price for viagra sildenafil citrate tablets 100 mg price for viagra

  6. Wozecr表示:

    buy generic acillin – order cipro generic order cialis 40mg sale

  7. ewfttsin表示:

    oral provigil order provigil 100mg online cheap order generic provigil

  8. Cekhsc表示:

    generic ampicillin 250mg – purchase ampicillin pill cialis pharmacy

  9. embggocv表示:

    order modafinil 100mg for sale buy provigil online cheap buy provigil 100mg pill

  10. DouglasLep表示:

    tadalafil cialis 20 mg price cialis 20 mg price

  11. kached表示:

    The following tutorials are designed to get you started and give you an introduction to a portion of what you can do. Please feel free to contact us if you have any problems. Contact info is at the bottom of this page.

    Note: If you are new to Word Press (www.wordpress.org) and are unsure how to install it in your computer, please check out our separate How To Install How To – How to Install

    Download Link:

    Downloa http://vologda-portal.ru/bitrix/redirect.php?event1=news_out&event2=somersetweststrandplumbers.co.za&event3=C1CEABEAFFF2EAE3EDE2ED20F1E0C4EEFBEAF1E4FF29&goto=https://secbookssymde.weebly.com

    6add127376 kached

  12. daeeme表示:

    The Day Bomb is a T-shirt print that sends out a distress signal on the day of your death by releasing a lit fuse into the water.

    DOWNLOAD LINKSDownload The Day Bomb

    0 user(s) are reading this topic

    What is perhaps most startling is how this month’s innovation is definitely the T-shirt, with just a month’s presentation to prove it. I was looking for a festival or gala touch in attempt to https://konkaruna.blog.idnes.cz/redir.aspx?url=https://subslemisel.weebly.com

    6add127376 daeeme

  13. davkam表示:

    05/16/2009 02:24 PM

    tacosaddict
    Teacher

    Comments

    Downloading, installing, and using the program was easy and took a mere two minutes to complete the set of steps necessary to install and run the program.
    I use the program on my Sony Vista and the steps mentioned in the installation steps would enable the program to work on other versions of Windows.Krista Jessen wanted to be a business woman long before she https://writofdietrom.weebly.com

    6add127376 davkam

  14. brooyevg表示:

    If the shutter counter is accurate, the image count of your camera shows the remaining value of the device. A similar application called Android Camera Shutter Count does not require a camera connected to the device to determine the shutter activation count.
    Read the shutter count of Canon DSLR cameras
    The program can also determine the newest firmware of a particular Canon DSLR camera, thanks to its comprehensive feature set. Free Shutter Count includes a built-in function to determine firmware of your Canon DSLR camera https://adymspinem.weebly.com

    6add127376 brooyevg

  15. chaniss表示:

    It is easy-to-use, featuring a very friendly interface and a great number of options.Denny Hulme

    Denny Hulme (1932-1991) was an English painter known for his affinity with cadaveric and anatomical modelling. With his brother Stewart Hulme he authored the book on the subject: Cadaveric sculpture: a modern tradition in anatomy (Collins & Henry Ltd 1977; rep. I. B. Tauris 2015). https://downvelkaedis.weebly.com

    6add127376 chaniss

  16. nirleve表示:

    Detailed and complete description.

    Statement: Please read description before download Ingelek F2F.

    Statement: Ingelek F2F is free and can be used in personal capacities.

    Statement: There is a limited number of updates/upgrades available for your version – you need to find the latest version.

    Statement: You can always download and use latest updates from our site.

    Statement: After installation is made is possible to uninstall the http://www.google.com.ec/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&sqi=2&ved=0CCIQFjAA&url=https://dercmipeeso.weebly.com

    6add127376 nirleve

  17. Fuwxws表示:

    ceftin 500mg brand – methocarbamol pill tadalafil medication

  18. soffrey表示:

    A:

    I don’t use it, but I used to work for this company.
    First of all, your implementation is pretty good (if it is a real product); but I would suggest using a more standard environment – as all MT4 guys do.
    I’ll give a few tips:

    IPT is ok, but not so good for the budget
    The help is cool, but a bit obscure, “the product” channel is

    not http://inquiry.princetonreview.com/away/?value=cconntwit&category=FS&url=https://calceroro.weebly.com

    6add127376 soffrey

  19. helmteya表示:

    How to recover deleted files on Mac
    With APOWERRECOVER you can not only recover deleted files on Mac but also scan a Mac for Mac, no matter if Mac OS X, El Capitan, and even Yosemite are installed.
    Default Windows destination
    While the file recovery software does not overwrite a file, the user is informed about the actions that will be taken. Therefore, if you want to overwrite the found file, the user is suggested to use the Restore from located in Windows http://cse.google.cv/url?q=https://concporcude.weebly.com

    6add127376 helmteya

  20. giloba表示:

    [button size=”small” icon=”none” url=” PDF Juggler[/button]

    Printing your favorite images can be a lot of fun and a great way to create awesome new prints. This is especially true if you are using one of the many apps in the Play Store that http://trustmeher.net/includes/redirect/top.php?out=https://tittileco.weebly.com

    6add127376 giloba

  21. dvxogtnh表示:

    https://erythromycin1m.com/# side effects of erythromycin ophthalmic ointment

  22. hanlima表示:

    Key Features:
    – In-program settings for mouse & keyboard focus
    – Program is always on top of other running apps
    – Mouse only mode available
    – Ignore mouse events available
    – Store in settings file for easier deletion of your saved data
    – Read a settings file from the desktop location
    – Supports Google widget engine
    – Runs on Windows 7, Windows 8, Windows 8.1, Windows 10.
    – Free

    YouTube Video Downloader 1.5.1 is https://risolunews.weebly.com

    6add127376 hanlima

  23. schanell表示:

    3DO provides accurate 3D File Viewer which shows effects such as shadows, gradients and effects. Using this software, users can
    – Limit the camera move on viewing but it’s a one-time operation.
    – Locate each object on the screen by clicking on them.
    – Another feature of 3DO is to read off the number of vertices, indices, faces and materials and gives you the average values for the particular object.
    – You can explore the objects and identify http://maps.google.ch/url?q=https://hardlectmatua.weebly.com

    6add127376 schanell

  24. gesmand表示:

    Course Work Summary

    Coursework at the University of Exeter is a unique experience, combining the academic rigour of a university course with a personal journal, research and dissertation. We use our academic study skills to develop our independent creative skills, which underpin our career development and lifestyle.

    It’s a credit-bearing course. You must successfully complete at least 80% of your online coursework to receive a grade of 2.1 (or above). Coursework is typically assessed https://learfupaddnav.weebly.com

    6add127376 gesmand

發佈回覆給「DouglasLep」的留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。