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.......
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With