Retina display: How to display images in native pixel resolution in Finder and Preview

1.5k views Asked by At

This is a pseudo question to share my own trick and script below.

The point is to be able to display image pixel for pixel on Retina displays. This is mainly useful for high resolution image and/or for developers working on HDPI version of images.

The solution works well only if the display setting is set to 2:1 ratio in the OS X preferences. Beware, late 2016 MacBook Pro default setting is not set to 2:1 by default. You should set it on the medium setting to get it right.

1

There are 1 answers

0
Max_B On

Finder : the simple trick is to give a name ending with @2x (before the extension): [email protected] . Then when using Quick Look feature the image is pixel-wise. As this naming scheme is recommended for retina images, both normal and HDPI images display at same size, as expected, the retina being sharper.

Preview : In preview, the DPI resolution of an image is interpreted as normal if it is set to 72dpi. By setting it to 144, you get the right display ratio. One can achieve the same effect at 72dpi by changing the display scale to 50%, but the scale setting does not stick to the image file while the DPI setting does. Change it through the Tools->Size menu item.

Here below is a small applescript to automate 144dpi setting from the Finder.

tell application "Finder"
repeat with item_cour in selection as list
    if word 1 of (the kind of item_cour as text) is "Image" then
        set path_cour to POSIX path of (item_cour as text)
        do shell script "p_cour='" & path_cour & "';
        tags=$(xattr -px com.apple.metadata:_kMDItemUserTags \"$p_cour\");
        f_info=$(xattr -px com.apple.FinderInfo \"$p_cour\");
        sips -s dpiHeight 144 -s dpiWidth 144 \"$p_cour\";
        xattr -wx com.apple.FinderInfo '$f_info' \"$p_cour\";
        xattr -wx com.apple.metadata:_kMDItemUserTags \"$tags\" \"$p_cour\" "
        -- do shell script "convert \"" & path_cour & "\" -set units PixelsPerInch -density 144 \"" & path_cour & "\""
    end if
end repeat
end tell

Since the sips command does not preserve tags, the script includes 4 lines to get and set them back to the file after it has been modified, using the xattr command.

To install the script: open the script editor, create a new document, paste the code and save it into the ~/Library/Scripts/Finder folder. Be sure to check the Show the Script Menu option in Script editor preference.

To use the script: select image file(s) in Finder and activate the script from the menu.