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...

17,641 Responses

  1. MasonGed表示:

    Apres le paiement, le Code promo de la machine a sous 1xbet devient disponible et peut etre active par le joueur a tout moment. Il y a beaucoup d’offres dans la vitrine des codes promotionnels. Dans la plupart des cas, ils couvrent la section du casino, mais souvent dans la vitrine sont publies des codes interessants pour la Conclusion a des conditions preferentielles des Paris Express, pour obtenir un cashback pour les Paris perdus. La vitrine est mise a jour assez souvent.

  2. MichaelGed表示:

    Offre speciale 1xBet Obtenez un bonus sportif supplementaire de 200% jusqu’a 130 €/$ avec le codes promo gratuits pour 1xbet, en plus du bonus de bienvenue standard de 1950$ et de 150 tours gratuits au casino. Profitez de cette opportunite pour jouer et gagner de l’argent grace aux paris sportifs. Chez nous, tout le monde peut devenir gagnant !

  3. JohnGed表示:

    Le code promo 1xbet. Enregistrez-vous des a present avec notre code promotionnel 1xBet valable jusqu’en 2024 pour beneficier d’un bonus de 200% sur votre premier depot. Utilisez le code de bonus lors de l’ouverture de votre nouveau compte 1xbet afin de recevoir votre bonus de bienvenue de 130$. L’enregistrement est autorise pour les personnes ayant atteint l’age de 18 ans et residant dans les pays ou l’activite du bookmaker n’est pas limitee au niveau legislatif.

  4. KyleGed表示:

    Qu’est-ce qu’une «Vitrine de codes promotionnels»?
    Ceci est une section speciale sur le site du bookmaker 1xbet multicode aujourd’hui, qui contient tous les codes promotionnels actuels. Sur la vitrine, les joueurs sont disponibles codes bonus pour les Paris sportifs, pour la section avec le jeu. Chaque code peut etre echange contre des points promo en fonction des denominations.

  5. AlexanderGed表示:

    Le 1xbet code promo tours gratuits 2024 pour beneficier d’une offre VIP de 100% jusqu’a 130€ sur les paris sportifs ou de 1950€ + 150 tours. Tous les nouveaux joueurs ayant utilise le code lors de leur inscription recoivent un bonus de bienvenue. Ce code bonus special vous permettra de recevoir un bonus augmente lors de votre inscription sur le site du bookmaker 1xBet.com ! Ne manquez pas cette occasion et inscrivez-vous des maintenant avec le code promo 1xbet pour obtenir un bonus allant jusqu’a 130 €/$.

  6. WONDERFUL Post.thanks for share..extra wait .. ?

  7. SEO_iqMa表示:

    раскрутка и продвижение сайтов в москве http://www.prodvizhenie-sajtov-v-moskve115.ru/ .

  8. Rdilzh表示:

    buy generic cyclobenzaprine – purchase enalapril generic vasotec 5mg ca

  9. SEO_ihMa表示:

    продвижение сайтов в москве и московской области http://prodvizhenie-sajtov-v-moskve115.ru/ .

  10. SEO_rfMa表示:

    продвижение сайтов в москве с оплатой за результат https://prodvizhenie-sajtov-v-moskve115.ru .

  11. link bokep表示:

    Hi there this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding experience
    so I wanted to get advice from someone with
    experience. Any help would be enormously appreciated!

  12. SEO_zgMa表示:

    seo продвижение корпоративных сайтов в москве prodvizhenie-sajtov-v-moskve115.ru .

  13. GeorgeGed表示:

    code promo pari gratuit 1xbett utilisez le code bonus pour obtenir un bonus VIP de 100% jusqu’a 130€ pour les Paris sportifs, ainsi qu’un bonus de casino de 1950 € + 150 tours de machines a sous. En utilisant le code promotionnel, vous pouvez vous attendre a ce que vos gains soient aussi eleves que dans le cas du plus grand bookmaker 1xbet. Tous les joueurs des pays suivants peuvent utiliser le code lors de l’inscription et recevoir un bonus de bienvenue:

  14. HarryGed表示:

    Quelle est la mise minimale et la limite minimale de 1xBet?
    Conformement aux regles du bookmaker, le depot minimum dans le bureau est de 1$.code promo de 1xbet La mise minimale est de 0,2 $ou l’equivalent de ce montant dans une autre monnaie de jeu.

  15. CharlesGed表示:

    Utilisez le Code promo de pari gratuit 1xbet aujourd’hui 2024 et profitez de l’offre VIP 1xBet de 200% jusqu’a 78 000 XOF sur les paris sportifs. Inscrivez-vous avec un code promotionnel et recevez un bonus de bienvenue. Vous pouvez utiliser l’argent du bonus pour parier sur des sports ou jouer dans des casinos en ligne. La promotion 2024 est valable pour tous les nouveaux clients.

  16. DanielGed表示:

    Le Code promo de pari gratuit 1xbet aujourd’hui, utilisez-le lors de l’inscription et obtenez un bonus de 200% jusqu’a 130$. Seuls les nouveaux joueurs peuvent obtenir le bonus. Ce contrat bonus est valable jusqu’au 31 decembre 2024. Apres le depot, le joueur recoit sur le compte bonus le montant des bonus pour les Paris de 100% du montant du depot, mais pas plus de $100. Pour recuperer le bonus recu, le joueur doit placer au moins cinq Paris dans les cinq jours suivants. Pour les Paris, vous devez faire un Express avec 3 evenements ou plus avec des cotes d’au moins 1,40.

  17. WilliamGed表示:

    Le 1x pari code promo gratuit vous offre un bonus de bienvenue pour une simple inscription allant jusqu’a 130 $. Copiez simplement le code promotionnel et utilisez-le lors de l’inscription. Ceci est la version la plus volumineuse de l’enregistrement, cependant, c’est l’enregistrement complet et ouvre le joueur un acces complet aux fonctionnalites de la plate-forme de jeu.

  18. GeorgeGed表示:

    code promo 1xbet tchad 2024 tous les details sur les bonus de bienvenue. Enregistrez-vous des maintenant avec notre offre speciale 1xBet 2024 pour beneficier d’un bonus de bienvenue de 100% jusqu’a 130$. Tous les nouveaux joueurs recoivent un bonus de bienvenue de 1xBet pour la creation d’un compte avec un code promotionnel.

  19. EthanGed表示:

    code promotionnel 1xbett utilisez le code bonus pour obtenir un bonus VIP de 100% jusqu’a 130€ pour les Paris sportifs, ainsi qu’un bonus de casino de 1950 € + 150 tours de machines a sous. En utilisant le code promotionnel, vous pouvez vous attendre a ce que vos gains soient aussi eleves que dans le cas du plus grand bookmaker 1xbet. Tous les joueurs des pays suivants peuvent utiliser le code lors de l’inscription et recevoir un bonus de bienvenue:

  20. JamesGed表示:

    Apres le paiement, le Bonus du code promo 1xbet devient disponible et peut etre active par le joueur a tout moment. Il y a beaucoup d’offres dans la vitrine des codes promotionnels. Dans la plupart des cas, ils couvrent la section du casino, mais souvent dans la vitrine sont publies des codes interessants pour la Conclusion a des conditions preferentielles des Paris Express, pour obtenir un cashback pour les Paris perdus. La vitrine est mise a jour assez souvent.

  21. Hi to all, the contents existing at this web site are really amazing for people knowledge, well, keep up the good
    work fellows.

  22. Great site! I recommend to everyone!kms pico

  23. SEO_niMa表示:

    продвижение сайтов в москве и россии http://www.prodvizhenie-sajtov-v-moskve115.ru .

  24. SEO_gqMa表示:

    продвижение сайтов в москве в топ prodvizhenie-sajtov-v-moskve115.ru .

  25. Kazanmak icin harika bir kumarhane Sweet bonanza

  26. SEO_iaMa表示:

    продвижение сайтов в москве цена https://prodvizhenie-sajtov-v-moskve115.ru .

  27. Adrianjug表示:

    KMSpico Download | Official KMS Website New July 2024
    office toolkit скачать
    Are you looking for the best tool to activate your Windows & Office? Then you should download and install KMSpico, as it is one of the best tools everyone should have. In this article, I will tell you everything about this fantastic tool, even though I will also tell you if this is safe to use.

    In this case, don’t forget to read this article until the end, so you don’t miss any critical information. This guide is for both beginners and experts as I came up with some of the rumours spreading throughout the internet.

    Perhaps before we move towards downloading or installing a section, we must first understand this tool. You should check out the guide below on this tool and how it works; if you already know about it, you can move to another section.
    What is KMSPico?
    KMPico is a tool that is used to activate or get a license for Microsft Windows as well as for MS Office. It was developed by one of the most famous developers named, Team Daz. However, it is entirely free to use. There is no need to purchase it or spend money downloading it. This works on the principle of Microsft’s feature named Key Management Server, a.k.a KMS (KMSPico named derived from it).

    The feature is used for vast companies with many machines in their place. In this way, it is hard to buy a Windows License for each device,, which is why KMS introduced. Now a company has to buy a KMS server for them and use it when they can get a license for all their machines.

    However, this tool also works on it, and similarly, it creates a server on your machine and makes it look like a part of that server. One thing different is that this tool only keeps the product activated for 180 days. This is why it keeps running on your machine, renews the license keys after 180 days, and makes it a permanent activation.

    KMSAuto Net
    Microsoft Toolkit
    Windows Loader
    Windows 10 Activator
    Features
    We already know what this tool means, so let’s talk about some of the features you are getting along with KMSPico. Reading this will surely help you understand whether you are downloading the correct file.

    Ok, so here are some of the features that KMSPico provides:

    Activate Windows & Office

    We have already talked about this earlier, as using this tool, you will get the installation key for both Microsoft Products. Whether it is Windows or Office, you can get a license in no time; however, this supports various versions.

    Supports Multi-Arch

    Since this supports both products, it doesn’t mean you have to download separate versions for each arch. One version is enough, and you can get the license for both x32-bit or even the x64-bit.

    It Is Free To Use

    Undoubtedly, everything developed by Team Daz costs nothing to us. Similarly, using this tool won’t cost you either, as it is entirely free. Other than this, it doesn’t come with any ads, so using it won’t be any trouble.

    Permanent License

    Due to the KMS server, this tool installs on our PC, we will get the license key for the rest of our lives. This is because the license automatically renews after a few days. To keep it permanent, you must connect your machine to the internet once 180 days.

    Virus Free

    Now comes the main feature of this tool that makes it famous among others. KMSPico is 100% pure and clean from such viruses or trojans. The Virus Total scans it before uploading to ensure it doesn’t harm our visitors.

  28. Douglasslida表示:

    KMSpico: What is it?
    kmspico что это за программа и нужна ли она
    Operating systems and Office suites are among the primary Microsoft software items that still need to be paid for. Some consumers may find alternate activation methods due to the perceived expensive cost of these items. There may be restrictions, unforeseen interruptions, and persistent activation prompts if these items are installed without being properly activated.

    Our KMSpico app was created as a solution to this issue. By using this program, customers may access all of the functionality of Microsoft products and simplify the activation procedure.
    KMSPico is a universal activator designed to optimize the process of generating and registering license codes for Windows and Office. Functionally, it is similar to key generators, but with the additional possibility of automatic integration of codes directly into the system. It is worth paying attention to the versatility of the tool, which distinguishes it from similar activators.
    The above discussion primarily focused on the core KMS activator, the Pico app. Understanding what the program is, we can briefly mention KMSAuto, a tool with a simpler interface.

    By using the KMSPico tool, you can setup Windows&Office for lifetime activation. This is an essential tool for anybody looking to reveal improved features and go beyond limitations. Although it is possible to buy a Windows or Office key.

    KMSPico 11 (last update 2024) allows you to activate Windows 11/10/8 (8.1)/7 and Office 2021/2019/2016/2013/2010 for FREE.

  29. I’m really enjoying the theme/design of your web site. Do you ever run into any internet browser compatibility issues? A couple of my blog readers have complained about my blog not working correctly in Explorer but looks great in Opera. Do you have any advice to help fix this problem?

  30. Great site! I recommend to everyone!kmspico download

發佈留言

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