LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2004, 08:07 PM   #1
smcallis
LQ Newbie
 
Registered: Jun 2004
Posts: 3

Rep: Reputation: 0
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?

Last edited by smcallis; 06-29-2004 at 08:20 PM.
 
Old 06-29-2004, 08:55 PM   #2
mhiggins
Member
 
Registered: Feb 2004
Posts: 140

Rep: Reputation: 15
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/
 
Old 06-30-2004, 12:13 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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
 
Old 06-30-2004, 12:50 PM   #4
smcallis
LQ Newbie
 
Registered: Jun 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Perfect!

That's exactly what I was looking for, that'll work great! Thanks!
 
Old 06-30-2004, 12:53 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
My pleasure.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to do copying and ISO image creating, etc. satimis Programming 2 09-19-2004 09:47 PM
ksh directory comparison script SeT Programming 4 08-30-2004 11:57 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration