相关疑难解决方法(0)

如何在javascript中检查图像是否是损坏的图像

我从 Twitter 获取个人资料图像并将图像 URL 存储在我的数据库中。某些网址给出了损坏的图像,其中网址以图像扩展名结尾,任何人都可以帮助我检查图像是有效图像还是损坏的图像。如果存在损坏的图像,我需要显示默认图像..

var image = opinionmakers[i].user_image;

                if (type == 'Twitter' && image.match(/jpeg/)) {
                    img = image.slice(0, -12) + ".jpeg";

                } else if (type == 'Twitter' && image.match(/jpg/)) {
                    img = image.slice(0, -11) + ".jpg";

                } else if (type == 'Twitter' && image.match(/JPG/)) {
                    img = image.slice(0, -11) + ".JPG";

                } else if (type == 'Twitter' && image.match(/png/)) {
                    img = image.slice(0, -11) + ".png";

                } else if (type == 'Twitter' && image.match(/gif/)) {
                    img = image.slice(0, -11) …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

javascript ×1

jquery ×1