Comparing the data in two folders

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
laanes
Forum Newbie
Posts: 7
Joined: Thu Jan 28, 2010 4:38 am

Comparing the data in two folders

Post by laanes »

Hello!

I have two folders. The first folder holds random size images and the second one holds static size images (300x180). How can write a script that compares those two folders? All the images added to the first folder should be resized automatically and then added to the second folder.

Can anyone come up with a working solution ?

All best,
laanes
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Comparing the data in two folders

Post by tr0gd0rr »

So you have something like "beach.jpg" in one folder and then "beach.300x180.jpg" in the other? If you have a naming convention, it should be easy to tell which images in the first folder are new. e.g. use `new DirectoryIterator` to get the list of filenames for each folder.

If you need to do image analysis to find images that are equivalent, you would need to do something fancy. I believe in image magick there are some tools to compare image similarity. But go with a simple naming convention instead!
laanes
Forum Newbie
Posts: 7
Joined: Thu Jan 28, 2010 4:38 am

Re: Comparing the data in two folders

Post by laanes »

tr0gd0rr wrote:So you have something like "beach.jpg" in one folder and then "beach.300x180.jpg" in the other? If you have a naming convention, it should be easy to tell which images in the first folder are new. e.g. use `new DirectoryIterator` to get the list of filenames for each folder.

If you need to do image analysis to find images that are equivalent, you would need to do something fancy. I believe in image magick there are some tools to compare image similarity. But go with a simple naming convention instead!
Can You provide some more code or an example ?

It sounds like a possible solution indeed.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Comparing the data in two folders

Post by tr0gd0rr »

As far as `DirectoryIterator`, look at the example in the php manual. As far as copying files, use `copy()`. As far as naming the files, you can use `pathinfo()` in php 5.2 to get the filename and extension and then add a size string in between. Before php 5.2 maybe use `explode()` to separate the file name from the file extension. As far as getting image size, use `getimagesize()`.
Post Reply