Check Image Dimensions Without getimagesize()

In a forthcoming project, it was necessary to check the dimensions of a remote image before deciding to cache it or not. While the PHP native function getimagesize() exists, it has some pitfalls. The biggest being: it relies on allow_url_fopen being enabled. While allow_url_fopen is not inherently dangerous, many web hosts do not have it set to prevent issues caused by inexperienced users (including Additionally, getimagesize() will retrieve the entire image—a waste of bandwidth, and time. This guide will cover finding the dimensions of images in the PNG and GIF formats with a word on JPEG and why it makes life difficult.

Download Sources

Continue reading