looping trough directories + intersecting matching images + merging images & reducing quality
Test page: http://arielbarkan.com/demo/php_task/index.php
Github page: https://github.com/ArielBarkan/php_task

Image saved:
Path = 00a2dfb5620346a6aee2b0a0a0597bfb3259b0af.jpg
Quality = 76%
oldImgSize = 52390 bytes
newImgSize = 50078 bytes
diff between oldImgSize and newImgSize = 4.4130559267036%

Image saved:
Path = 00a5d783b1328bdff7cede688a3524520a5000b3.jpg
Quality = 73%
oldImgSize = 54098 bytes
newImgSize = 52153 bytes
diff between oldImgSize and newImgSize = 3.5953269991497%

Image saved:
Path = 0a0ab9107b101653d748b0442366e7b456e4019e.jpg
Quality = 76%
oldImgSize = 55199 bytes
newImgSize = 52635 bytes
diff between oldImgSize and newImgSize = 4.6450116849943%

Image saved:
Path = 0a0e0de1ac3f4960316858407b0bb924aadb6c8e.jpg
Quality = 76%
oldImgSize = 63517 bytes
newImgSize = 60344 bytes
diff between oldImgSize and newImgSize = 4.9955130122644%

Image saved:
Path = 0a0f1075bd14672c04b14ed6c092410688f98511.jpg
Quality = 76%
oldImgSize = 49553 bytes
newImgSize = 47244 bytes
diff between oldImgSize and newImgSize = 4.6596573365891%

Image saved:
Path = 0a1ca9f58f75ec5242958d690eeabc75566a07b9.jpg
Quality = 73%
oldImgSize = 47304 bytes
newImgSize = 45609 bytes
diff between oldImgSize and newImgSize = 3.5832064941654%

Image saved:
Path = 0a1d168655a7e2ddbb495e2e0116fcf8fe5a525b.jpg
Quality = 73%
oldImgSize = 40757 bytes
newImgSize = 39742 bytes
diff between oldImgSize and newImgSize = 2.4903697524352%

Image saved:
Path = 0a1e76a9a9416cc47a2efa0284e4cb38fbbf2407.jpg
Quality = 73%
oldImgSize = 45354 bytes
newImgSize = 43748 bytes
diff between oldImgSize and newImgSize = 3.541032764475%

Image saved:
Path = 0a1f3a9ab9d6e3f656f64e6dbb63f9fd3d025baf.jpg
Quality = 76%
oldImgSize = 59418 bytes
newImgSize = 56770 bytes
diff between oldImgSize and newImgSize = 4.4565619845838%

Image saved:
Path = 0a1f696d11616de89bf4ee4cab1c865d537e54b2.jpg
Quality = 76%
oldImgSize = 43076 bytes
newImgSize = 41095 bytes
diff between oldImgSize and newImgSize = 4.5988485467546%

Image saved:
Path = 0a2b7ddf79e8ee519075277f4f98d161b38390fe.jpg
Quality = 73%
oldImgSize = 42927 bytes
newImgSize = 41461 bytes
diff between oldImgSize and newImgSize = 3.4151000535793%

Image saved:
Path = 0a2ceca91bfdc7f679d6938a003a59852ae4aba7.jpg
Quality = 73%
oldImgSize = 42795 bytes
newImgSize = 41238 bytes
diff between oldImgSize and newImgSize = 3.6382754994742%

Image saved:
Path = 0a2e567b16f51a54e13f260b3668554348516904.jpg
Quality = 73%
oldImgSize = 40183 bytes
newImgSize = 38863 bytes
diff between oldImgSize and newImgSize = 3.2849712565015%

Image saved:
Path = 0a2fc8d0911b414fc8f9197dcefe5a1b0d5551d1.jpg
Quality = 73%
oldImgSize = 40199 bytes
newImgSize = 38830 bytes
diff between oldImgSize and newImgSize = 3.4055573521729%

Image saved:
Path = 0a2fcda5952bf16ff0ba8973965f40bbab29e1cf.jpg
Quality = 76%
oldImgSize = 61070 bytes
newImgSize = 58214 bytes
diff between oldImgSize and newImgSize = 4.6766006222368%

Image saved:
Path = 0a3a22700cc8b622bb6f95f06eb42b136ef0b220.jpg
Quality = 76%
oldImgSize = 45626 bytes
newImgSize = 43512 bytes
diff between oldImgSize and newImgSize = 4.633323105247%

Image saved:
Path = 0a3b194f93a2d288fda3bd6902ff765171668750.jpg
Quality = 76%
oldImgSize = 42391 bytes
newImgSize = 40276 bytes
diff between oldImgSize and newImgSize = 4.9892665896063%

Image saved:
Path = 0a3bea7fed7b71d07d4b72b9c982162ed5df3fc9.jpg
Quality = 76%
oldImgSize = 49918 bytes
newImgSize = 47825 bytes
diff between oldImgSize and newImgSize = 4.1928763171601%

Image saved:
Path = 0a3e1e8e3ab34ba6abfb1286a8454db85f1e3691.jpg
Quality = 76%
oldImgSize = 62534 bytes
newImgSize = 59829 bytes
diff between oldImgSize and newImgSize = 4.3256468481146%

Image saved:
Path = 0a4b3ec23b8c661d44e306f5c603b92ade33114b.jpg
Quality = 73%
oldImgSize = 56405 bytes
newImgSize = 54430 bytes
diff between oldImgSize and newImgSize = 3.5014626362911%

Image saved:
Path = 0a4b880453f7ba521305e77ec2770896d91915aa.jpg
Quality = 73%
oldImgSize = 41736 bytes
newImgSize = 40268 bytes
diff between oldImgSize and newImgSize = 3.5173471343684%

Image saved:
Path = 0a4bb035bbbde9e56b81b5ae99f8629a1e8eb844.jpg
Quality = 73%
oldImgSize = 40013 bytes
newImgSize = 38517 bytes
diff between oldImgSize and newImgSize = 3.7387848949092%

Image saved:
Path = 0a4c47e1c9c2a46706f4d1c34c779a10b6306e73.jpg
Quality = 76%
oldImgSize = 45571 bytes
newImgSize = 43558 bytes
diff between oldImgSize and newImgSize = 4.417282921156%

Image saved:
Path = 0a4db988ba4019ff21cd3c85d917e1bd1424ab1d.jpg
Quality = 76%
oldImgSize = 45748 bytes
newImgSize = 43732 bytes
diff between oldImgSize and newImgSize = 4.4067500218589%

Image saved:
Path = 0a4ddc9683841eb031d78e833f7c3afb47b457d7.jpg
Quality = 76%
oldImgSize = 47043 bytes
newImgSize = 45068 bytes
diff between oldImgSize and newImgSize = 4.1982866738941%

Image saved:
Path = 0a4e3c4f9836e878275ed6f4c81418d5fcbc269b.jpg
Quality = 73%
oldImgSize = 58352 bytes
newImgSize = 56322 bytes
diff between oldImgSize and newImgSize = 3.478886756238%

Image saved:
Path = 0a4e89bcbc1813da88f066184bb0de803bc99ccb.jpg
Quality = 76%
oldImgSize = 46043 bytes
newImgSize = 43980 bytes
diff between oldImgSize and newImgSize = 4.4805942271355%

Image saved:
Path = 0a4fca65d3b9b2403612896113a40cd6e397f75b.jpg
Quality = 73%
oldImgSize = 45918 bytes
newImgSize = 44284 bytes
diff between oldImgSize and newImgSize = 3.5585173570277%

Image saved:
Path = 0a5ab72abdc37a8bc6080547e4b2fb7629c408cb.jpg
Quality = 76%
oldImgSize = 53205 bytes
newImgSize = 50830 bytes
diff between oldImgSize and newImgSize = 4.4638661779908%

Image saved:
Path = 0a5adac2a0d54b8e9f2071bb9ff8c13d970cfbc3.jpg
Quality = 76%
oldImgSize = 44104 bytes
newImgSize = 42126 bytes
diff between oldImgSize and newImgSize = 4.4848539814983%

Image saved:
Path = 0a5af343f5766dc0f36df9ee30825c69112a0a99.jpg
Quality = 73%
oldImgSize = 46677 bytes
newImgSize = 44909 bytes
diff between oldImgSize and newImgSize = 3.7877327163271%

Image saved:
Path = 0a5afcb4cadb80ae4c574293b46133ad08d152ff.jpg
Quality = 76%
oldImgSize = 47655 bytes
newImgSize = 45559 bytes
diff between oldImgSize and newImgSize = 4.3982792991292%

Image saved:
Path = 0a5b829d26958934779c251f24ffa6ed15b72039.jpg
Quality = 76%
oldImgSize = 47418 bytes
newImgSize = 45246 bytes
diff between oldImgSize and newImgSize = 4.5805390358092%

Image saved:
Path = 0a5dd6d9185bad6e521909ad08f6526abd330b2d.jpg
Quality = 76%
oldImgSize = 50976 bytes
newImgSize = 48603 bytes
diff between oldImgSize and newImgSize = 4.655131826742%

Image saved:
Path = 0a5fc3323cbe845e9fe4412d7dea268c5a96bc17.jpg
Quality = 76%
oldImgSize = 43768 bytes
newImgSize = 41586 bytes
diff between oldImgSize and newImgSize = 4.9853774447085%