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
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.

Link to comment
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.

 

And the values i need to set manually ? e.g. $width = 300 and $height = 300 ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.