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
Comparing the data in two folders
Moderator: General Moderators
Re: Comparing the data in two folders
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!
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!
Re: Comparing the data in two folders
Can You provide some more code or an example ?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!
It sounds like a possible solution indeed.
Re: Comparing the data in two folders
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()`.