laanes Posted January 28, 2010 Share Posted January 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190095-comparing-the-data-in-two-folders/ Share on other sites More sharing options...
oni-kun Posted January 28, 2010 Share Posted January 28, 2010 You can list the files of both folders, and compare from there.. Something like this: <?php //Folder 1 foreach (glob("/folder1/*.jpg") as $filename) { echo "$filename size " . filesize($filename) . "<br/>\n"; list($width, $height) = getimagesize($image); echo "Dimensions: $width x $height"; } //Folder 2 foreach (glob("/folder2/*.jpg") as $filename) { echo "$filename size " . filesize($filename) . "<br/>\n"; list($width, $height) = getimagesize($image); echo "Dimensions: $width x $height"; } ?> I'm not 100% certain this code works, but should. Look up the glob function for more info. Quote Link to comment https://forums.phpfreaks.com/topic/190095-comparing-the-data-in-two-folders/#findComment-1002959 Share on other sites More sharing options...
laanes Posted February 1, 2010 Author Share Posted February 1, 2010 Would that actually change the dimensions of the file or just display it with those dimensions on the web ? Quote Link to comment https://forums.phpfreaks.com/topic/190095-comparing-the-data-in-two-folders/#findComment-1004942 Share on other sites More sharing options...
laanes Posted February 1, 2010 Author Share Posted February 1, 2010 You can list the files of both folders, and compare from there.. Something like this: <?php //Folder 1 foreach (glob("/folder1/*.jpg") as $filename) { echo "$filename size " . filesize($filename) . "<br/>\n"; list($width, $height) = getimagesize($image); echo "Dimensions: $width x $height"; } //Folder 2 foreach (glob("/folder2/*.jpg") as $filename) { echo "$filename size " . filesize($filename) . "<br/>\n"; list($width, $height) = getimagesize($image); echo "Dimensions: $width x $height"; } ?> I'm not 100% certain this code works, but should. Look up the glob function for more info. And the values i need to set manually ? e.g. $width = 300 and $height = 300 ? Quote Link to comment https://forums.phpfreaks.com/topic/190095-comparing-the-data-in-two-folders/#findComment-1004975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.