Blog for web designers

Detect duplicate image

Detect duplicate image

Hi folks, today in this tutorials I am going to show you how anyone can easily detect duplicate image inside the page and remove one of them. I am writing this tutorial because recently I have been working in a inbuilt wordpress project where the content and images was already loaded. My job was to create a new theme with existing content. When I import those content in the new theme I found that in all post there were same image repeating. One is coming from feature image and another one was hard coded inside the page. Both the image was coming form the same path. With trying with some simple jQuery script I was able to accomplished this job.

This is how I detect duplicate image with the help of jQuery.

Detect duplicate image with jQuery


$(function(){
    var srcs = [],
        temp;
    $("body img").filter(function(){
        temp = $(this).attr("src");
        if($.inArray(temp, srcs) < 0){
            srcs.push(temp);   
            return true;
        }
        return false;
    }).remove();
});

I hope you find this tutorial helpful. Thanks for reading.

Santosh Shah

My name is Santosh Shah and blogs at santosh-shah.com


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.