If you want to determine the size of an image file on a Linux system, for some types of image files, e.g., PNG or GIF files, you can just use the file command. E.g.:

$ file ~/Documents/System_Memory.png
/home/jdoe/Documents/System_Memory.png: PNG image data, 800 x 600, 8-bit/color RGBA, non-interlaced
$ file ~/Documents/recipes/asparagus-strawberry-salad.gif
/home/jdoe/Documents/recipes/asparagus-strawberry-salad.gif: GIF image data, version 89a, 250 x 153

But if you obtain information on a JPG/JPEG file with that command, it doesn't provide any information on the dimensions of the image.

$ file ~/Documents/Winter.jpg
/home/jdoe/Documents/Winter.jpg: JPEG image data, JFIF standard 1.02

If you install the exiv2 package, you can also display the dimensions of JPEG images as well as PNG, GIF, and other image formats.

$ exiv2 /home/jdoe/Documents/Winter.jpg
File name       : /home/jdoe/Documents/Winter.jpg
File size       : 105542 Bytes
MIME type       : image/jpeg
Image size      : 800 x 600
/home/jdoe/Documents/Winter.jpg: No Exif data found in the file
$ exiv2 /home/jdoe/Documents/System_Memory.png
File name       : /home/jdoe/Documents/System_Memory.png
File size       : 135335 Bytes
MIME type       : image/png
Image size      : 800 x 600
/home/jdoe/Documents/System_Memory.png: No Exif data found in the file
$ exiv2 /home/jdoe/Documents/recipes/asparagus-strawberry-salad.gif
File name       : /home/jdoe/Documents/recipes/asparagus-strawberry-salad.gif
File size       : 31346 Bytes
MIME type       : image/gif
Image size      : 250 x 153
/home/jdoe/Documents/recipes/asparagus-strawberry-salad.gif: No Exif data found in the file

Note: the reference to "No Exif data found in the file" indicates that the iamge file doesn't contain exchangeable image file format (Exiv) data, which a digital camera may store in an image file, such as a JPEG file. E.g., the camera might store geolocation data indicating the geographical locate where the picture was taken.

To install the exiv2 package on Red Hat Linux or CentOS systems, you can issue the command yum install exiv2.

Udemy Generic Category (English)120x600
# yum install exiv2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.lga7.us.voxel.net
 * epel: mirror.cogentco.com
 * extras: mirror.cs.pitt.edu
 * updates: mirror.genesisadaptive.com
Resolving Dependencies
--> Running transaction check
---> Package exiv2.x86_64 0:0.23-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package          Arch              Version               Repository       Size
 exiv2            x86_64            0.23-6.el7            base             82 k

Transaction Summary
Install  1 Package

Total download size: 82 k
Installed size: 196 k
Is this ok [y/d/N]: y
Downloading packages:
exiv2-0.23-6.el7.x86_64.rpm                                |  82 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : exiv2-0.23-6.el7.x86_64                                      1/1 
  Verifying  : exiv2-0.23-6.el7.x86_64                                      1/1 

  exiv2.x86_64 0:0.23-6.el7                                                     


Once it is installed, you can view information for the package with the rpm command using rpm -qi exiv2 and see the files included in the package with rpm -ql exiv2.

$ rpm -qi exiv2
Name        : exiv2
Version     : 0.23
Release     : 6.el7
Architecture: x86_64
Install Date: Sun 09 Jul 2017 11:31:45 AM EDT
Group       : Applications/Multimedia
Size        : 201126
License     : GPLv2+
Signature   : RSA/SHA256, Thu 03 Jul 2014 09:15:40 PM EDT, Key ID 24c6a8a7f4a80eb5
Source RPM  : exiv2-0.23-6.el7.src.rpm
Build Date  : Mon 09 Jun 2014 07:49:58 PM EDT
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.exiv2.org/
Summary     : Exif and Iptc metadata manipulation library
Description :
A command line utility to access image metadata, allowing one to:
* print the Exif metadata of Jpeg images as summary info, interpreted values,
  or the plain data for each tag
* print the Iptc metadata of Jpeg images
* print the Jpeg comment of Jpeg images
* set, add and delete Exif and Iptc metadata of Jpeg images
* adjust the Exif timestamp (that's how it all started...)
* rename Exif image files according to the Exif timestamp
* extract, insert and delete Exif metadata (including thumbnails),
  Iptc metadata and Jpeg comments
$ rpm -ql exiv2

You can see usage information for the program with exiv2 -h.

$ exiv2 -h
Usage: exiv2 [ options ] [ action ] file ...

Manipulate the Exif metadata of images.

  ad | adjust   Adjust Exif timestamps by the given time. This action
                requires at least one of the -a, -Y, -O or -D options.
  pr | print    Print image metadata.
  rm | delete   Delete image metadata from the files.
  in | insert   Insert metadata from corresponding *.exv files.
                Use option -S to change the suffix of the input files.
  ex | extract  Extract metadata to *.exv, *.xmp and thumbnail image files.
  mv | rename   Rename files and/or set file timestamps according to the
                Exif create timestamp. The filename format can be set with
                -r format, timestamp options are controlled with -t and -T.
  mo | modify   Apply commands to modify (add, set, delete) the Exif and
                IPTC metadata of image files or set the JPEG comment.
                Requires option -c, -m or -M.
  fi | fixiso   Copy ISO setting from the Nikon Makernote to the regular
                Exif tag.
  fc | fixcom   Convert the UNICODE Exif user comment to UCS-2. Its current
                character encoding can be specified with the -n option.

   -h      Display this help and exit.
   -V      Show the program version and exit.
   -v      Be verbose during the program run.
   -q      Silence warnings and error messages during the program run (quiet).
   -Q lvl  Set log-level to d(ebug), i(nfo), w(arning), e(rror) or m(ute).
   -b      Show large binary values.
   -u      Show unknown tags.
   -g key  Only output info for this key (grep).
   -n enc  Charset to use to decode UNICODE Exif user comments.
   -k      Preserve file timestamps (keep).
   -t      Also set the file timestamp in 'rename' action (overrides -k).
   -T      Only set the file timestamp in 'rename' action, do not rename
           the file (overrides -k).
   -f      Do not prompt before overwriting existing files (force).
   -F      Do not prompt before renaming files (Force).
   -a time Time adjustment in the format [-]HH[:MM[:SS]]. This option
           is only used with the 'adjust' action.
   -Y yrs  Year adjustment with the 'adjust' action.
   -O mon  Month adjustment with the 'adjust' action.
   -D day  Day adjustment with the 'adjust' action.
   -p mode Print mode for the 'print' action. Possible modes are:
             s : print a summary of the Exif metadata (the default)
             a : print Exif, IPTC and XMP metadata (shortcut for -Pkyct)
             t : interpreted (translated) Exif data (-PEkyct)
             v : plain Exif data values (-PExgnycv)
             h : hexdump of the Exif data (-PExgnycsh)
             i : IPTC data values (-PIkyct)
             x : XMP properties (-PXkyct)
             c : JPEG comment
             p : list available previews
   -P flgs Print flags for fine control of tag lists ('print' action):
             E : include Exif tags in the list
             I : IPTC datasets
             X : XMP properties
             x : print a column with the tag number
             g : group name
             k : key
             l : tag label
             n : tag name
             y : type
             c : number of components (count)
             s : size in bytes
             v : plain data value
             t : interpreted (translated) data
             h : hexdump of the data
   -d tgt  Delete target(s) for the 'delete' action. Possible targets are:
             a : all supported metadata (the default)
             e : Exif section
             t : Exif thumbnail only
             i : IPTC data
             x : XMP packet
             c : JPEG comment
   -i tgt  Insert target(s) for the 'insert' action. Possible targets are
           the same as those for the -d option, plus a modifier:
             X : Insert metadata from an XMP sidecar file <file>.xmp
           Only JPEG thumbnails can be inserted, they need to be named
   -e tgt  Extract target(s) for the 'extract' action. Possible targets
           are the same as those for the -d option, plus a target to extract
           preview images and a modifier to generate an XMP sidecar file:
             p[<n>[,<m> ...]] : Extract preview images.
             X : Extract metadata to an XMP sidecar file <file>.xmp
   -r fmt  Filename format for the 'rename' action. The format string
           follows strftime(3). The following keywords are supported:
             :basename:   - original filename without extension
             :dirname:    - name of the directory holding the original file
             :parentname: - name of parent directory
           Default filename format is %Y%m%d_%H%M%S.
   -c txt  JPEG comment string to set in the image.
   -m file Command file for the modify action. The format for commands is
           set|add|del <key> [[<type>] <value>].
   -M cmd  Command line for the modify action. The format for the
           commands is the same as that of the lines of a command file.
   -l dir  Location (directory) for files to be inserted from or extracted to.
   -S .suf Use suffix .suf for source files for insert command.



man page

Related articles:

  1. Determining an Image File's Dimensions with Command Line Tools