Jump to content

Comparing the data in two folders


laanes

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/190095-comparing-the-data-in-two-folders/
Share on other sites

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.

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 ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.