20
10
I have a random .PNG
file on my Mac. Actually I have about a hundred of them. What is the easiest way to get the pixel dimensions? (I.e, 100 pixels wide and 50 high, or whatever).
20
10
I have a random .PNG
file on my Mac. Actually I have about a hundred of them. What is the easiest way to get the pixel dimensions? (I.e, 100 pixels wide and 50 high, or whatever).
35
In Terminal, you can use the following:
$ sips -g pixelWidth Pictures/238337225.png
/Users/danielbeck/Pictures/238337225.png
pixelWidth: 1140
$ sips -g pixelHeight Pictures/238337225.png
/Users/danielbeck/Pictures/238337225.png
pixelHeight: 900
To extract the value only, use e.g.
$ sips -g pixelHeight Pictures/238337225.png | tail -n1 | cut -d" " -f4
900
To embed that in AppleScript:
set h to do shell script "sips -g pixelHeight /Users/danielbeck/Pictures/238337225.png | tail -n1 | cut -d' ' -f4"
set w to do shell script "sips -g pixelWidth /Users/danielbeck/Pictures/238337225.png | tail -n1 | cut -d' ' -f4"
display alert "Height: " & (h as text) & "
Width: " & (w as text)
Result:
Alternatively, you can read the Spotlight metadata:
mdls Pictures/238337225.png | grep kMDItemPixel
kMDItemPixelCount = 1026000
kMDItemPixelHeight = 900
kMDItemPixelWidth = 1140
To get the names and dimensions of all files in a directory:
$ mdls Pictures/* | grep "\(kMDItemDisplayName\|mMDItemPixel\)"
[...]
kMDItemDisplayName = "url.png"
kMDItemPixelCount = 16384
kMDItemPixelHeight = 128
kMDItemPixelWidth = 128
[...]
Or alternatively, using find
and sips
:
find /Users/danielbeck/Pictures -type f -name "*.png" -exec sips -g pixelWidth {} \; -exec sips -g pixelHeight {} \;
More more flexibility, wrap in a shell script:
$ cat dim.sh
#!/usr/bin/env bash
filename=$1
if [ ! -f "$filename" ] ; then
echo "$filename not found!";
exit 1
fi
h=$( mdls "$filename" | grep kMDItemPixelHeight | tail -n1 | cut -d= -f2 )
w=$( mdls "$filename" | grep kMDItemPixelWidth | tail -n1 | cut -d= -f2 )
osascript -e "tell application \"Finder\" to {activate, display alert \"$filename\\nWidth:$w\\nHeight:$h\"}"
Result after chmod +x dim/sh
:
$ ./dim.sh Pictures/flying_cars.png
You could easily extend the script to display dimensions for multiple files at once, or e.g. all png files in a certain directory. Output is as Finder dialog, so you can embed it into an Automator service:
Open Automator and select to create a Service that receives image files as input in any application.
Add a Run Shell Script action that receives input as arguments and enter the following:
dlg=
for f in "$@"
do
h=$( mdls "$f" | grep kMDItemPixelHeight | tail -n1 | cut -d= -f2 )
w=$( mdls "$f" | grep kMDItemPixelWidth | tail -n1 | cut -d= -f2 )
dlg="$dlg$f\nW:$w H:$h\n"
done
osascript -e "tell application \"Finder\" to {activate, display alert \"$dlg\"}"
exit 0
Save as Show Image Dimensions. Select a few image files in Finder and select Finder » Services » Show Image Dimensions or Right-click
on one of the files and [Services »] Show Image Dimensions
Oldie, but still a goodie! – Manngo – 2019-10-16T03:15:37.300
8
Find the file in a Finder window, and either:
Highlight the file and press ⌘ Cmd + ⌥ Option + I, or
Control-click the file and hold ⌥ Option so you can select "Show Inspector".
This will open an inspector which is similar to the Get Info window, but updates each time you select a file.
Now expand the "More info" section on the inspector. You will be able to see the PNG's dimensions and color depth, among other data. Select a new file to see its dimensions in the inspector.
2The weird thing is that when I open that window, what I see under "more info" is Title, Headline, and Last Opened . . . but no dimensions, color space, color profile, or alpha channel. My OS is 10.6.7 and my Finder is version 10.6.8; could that be the problem? – William Jockusch – 2011-04-20T05:24:50.770
2This feature depends on Spotlight to index the image's location. Are the picture in a non-indexed location? – Stephen Jennings – 2011-04-20T06:45:59.257
4
sadly the question was posted in 2011 and yosemite was released in 2014 – Francisco Tapia – 2015-09-28T16:51:40.753
1yeah, it was the number 1 search result when i looked for answer to this problem on Google, so i thought others would benefit from my answer – Sergi – 2015-09-28T19:56:00.430
2
The easiest way; open the images in Safari.
Select all the images. Then use Ctrl+Click context menu and choose Open With > Safari.
Optionally you can merge all the open Safari menus together into separate tabs using the Safari menu Window > Merge All Windows.
The top of the Safari window displays the image dimensions:
I find it really bizarre that this is the only option that worked for me. Why do I have to open a browser to view picture dimensions ?!? This is ridiculous. Thanks for the answer nevertheless – Michael – 2015-05-07T22:22:15.350
0
Here is how to use the Finder add a separate 'Dimensions' and 'Resolution' column to the list view of a folder.
Now the nice part.
Sometimes Resolution is not calculated or available and a dash will appear in the column. See attachment.
This still works as of macOS Sierra 10.12.6 I do not know if this folder setting sticks when the folder is moved to another user account, network folder, etc.
Screenshot: Folder in list view with Dimension and Resolution columns.
-1
Open the image in preview then go to tools>Show Inspector(⌘S). This will bring up a window that displays the image dimensions with pixels as the unit.
Doesn't that just show up when you view the file properties? – beatgammit – 2011-04-20T02:39:06.293
1I right click, then click "Get info", and don't see it. – William Jockusch – 2011-04-20T02:40:42.767