Consider a platform that has users, each user has an avatar that can be changed frequently. The platform offers an API to query for users and their avatars.
Now, each avatar should be send to an external API that processes the image, but a request is only neccessary if the image has changed (optimize rate limiting). The avatars will be checked periodically for changes. Now, to the actual question:
I am looking for an efficient way to store the identity of an image to determine if the image has changed. The previous image does not need to be saved (you could just compare it pixel by pixel then and there already exists an related question). Also, it does not matter if some images produce the same value
as it happens rarely (one additional request does not matter).
My first idea was to use the hashCode()
method of the Raster
class to compute a value that can be persisted in a database and easily compared. However, neither BufferedImage
nor Raster
override hashCode
.
public boolean hasAvatarChanged(BufferedImage image, int hashCode) {
// ...
}
So, this approach does not work.