Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting whether an image is corrupted or broken

I need to programmatically check whether the image that the user has selected as his wallpaper on my app is broken or corrupted....... basically I provide user with the option to choose his own image as wallpaper. Now when the images loads, I just want to keep a check on whether it is somehow corrupt or not.......

like image 320
Dilletante Avatar asked Mar 30 '12 07:03

Dilletante


People also ask

How do you check if image is corrupted or not?

The only way to check if file is corrupted is to try reading it as it is described in file format, ie. load BMP as BMP with reading BMP header, BMP data etc. There are many web pages that describe graphics file formats.

What does a corrupted photo look like?

When an image is corrupt, it may not open. If it does open, it may show gray bars, black bars or random colors over some part of the picture. Obviously, any amount of corruption is unacceptable, especially for professional photographers and graphic designers.

What does it mean when an image is broken?

These icons simply mean that an inserted image on your site cannot be found or displayed. Not only can they be frustrating, they can distort your page layout, which will affect user experience and the visual aspect of your website. Like broken links, broken images can happen for several reasons.

How does an image become corrupted?

So, why do photos get corrupt? There are a number of reasons which render the photos corrupt such as accumulation of bad sectors on the storage media, some bits missing, scratch on CDs/DVDs, split into chunks, etc.


1 Answers

If instead you are looking for a PHP solution instead of a javascript solution (which the potential duplicates do not provide), you can use GD's getimagesize() in PHP and see what it returns. It will return false and throw an error when the provided image format is not valid.

like image 183
objectified Avatar answered Oct 18 '22 10:10

objectified