LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Image Comparison With Bash Script (https://www.linuxquestions.org/questions/programming-9/image-comparison-with-bash-script-199293/)

smcallis 06-29-2004 08:07 PM

Image Comparison With Bash Script
 
Hey guys, I'm writing a little script that automatically downloads images from a webpage source every day. The link to download them from is a php script, which works just fine with wget. I can download the images, automatically number and rename them and store them away in a directory. The problem is, the script keeps a number in a file in the image directory which tells it what number image is the next to be downloaded. So whenever a new image is downloaded, it knows what number to use in the php URL to get it. The problem is, once you get to the end of the list, when you use a number > number of images available, the php script just returns the last posted picture. Unfortunately, the script relies on not being able to find the downloaded file to know that it wasn't available.

Does anyone know of a way to compare two images on the command line (say, if their dimensions and size are the same, they're equal) or know of a better way to do this?

mhiggins 06-29-2004 08:55 PM

You could compare file sizes?

I dont know what type of images they are but these command line tools are fantastic and can report all kinds of image information.

http://www.imagemagick.org/

Hko 06-30-2004 12:13 PM

Just use GNU's "cmp" tool. It made for comparing binary files, and you can assume it's installed on the mainstream Linux distributions.
Code:

#!/bin/bash

if cmp -s file1 file2 ; then
        echo "Files are the same"
else
        echo "Files are different"
fi


smcallis 06-30-2004 12:50 PM

Perfect!
 
That's exactly what I was looking for, that'll work great! Thanks!

Hko 06-30-2004 12:53 PM

My pleasure.


All times are GMT -5. The time now is 05:25 PM.