cd /usr/local/src
curl --remote-name --location ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.27a.tar.gz
tar -xzvf GraphicsMagick-1.3.27a.tar.gz
cd GraphicsMagick-1.3.27a
./configure CC=clang \
LDFLAGS="-L/usr/local/libjpeg/lib -L/usr/local/libpng/lib -L/usr/local/libtiff/lib" \
CPPFLAGS="-I/usr/local/libjpeg/include -I/usr/local/libpng/include -I/usr/local/libtiff/include" \
--prefix=/usr/local/mac-dev-env/graphicsmagick-1.3.27a
make
sudo make install
sudo ln -s mac-dev-env/graphicsmagick-1.3.27a /usr/local/graphicsmagick
echo 'export PATH=/usr/local/graphicsmagick/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
gm version
Reference
Installing graphicsmagick on Mac