I did such script a long time ago.
I should start by asking, how much disk space do you have for this?
Local images are cheap:
+--------+---------+
| number | size |
+--------+---------+
| 22 | 2108819 |
+--------+---------+
eswiktionary
+--------+--------+
| number | size |
+--------+--------+
| 14 | 390539 |
+--------+--------+
frwiktionary
+--------+--------+
| number | size |
+--------+--------+
| 6 | 702706 |
+--------+--------+
dewiktionary
+--------+---------+
| number | size |
+--------+---------+
| 104 | 4943453 |
+--------+---------+
enwikiquote
+--------+------+
| number | size |
+--------+------+
| 0 | NULL |
+--------+------+
eswikiquote
+--------+------+
| number | size |
+--------+------+
| 0 | NULL |
+--------+------+
frwikiquote
+--------+------+
| number | size |
+--------+------+
| 0 | NULL |
+--------+------+
dewikiquote
+--------+---------+
| number | size |
+--------+---------+
| 17 | 2236129 |
+--------+---------+
enwikibooks
+--------+-----------+
| number | size |
+--------+-----------+
| 2716 | 153301990 |
+--------+-----------+
eswikibooks
+--------+------+
| number | size |
+--------+------+
| 0 | NULL |
+--------+------+
frwikibooks
+--------+---------+
| number | size |
+--------+---------+
| 169 | 8244783 |
+--------+---------+
dewikibooks
+--------+------------+
| number | size |
+--------+------------+
| 7697 | 2772943547 |
+--------+------------+
but the commons files will start requiring a bit more space (about 1 TB):
enwiktionary
+--------+--------------+
| number | size |
+--------+--------------+
| 724855 | 154587222013 |
+--------+--------------+
eswiktionary
+--------+-------------+
| number | size |
+--------+-------------+
| 18938 | 12918158214 |
+--------+-------------+
frwiktionary
+--------+--------------+
| number | size |
+--------+--------------+
| 560321 | 146933557784 |
+--------+--------------+
dewiktionary
+--------+-------------+
| number | size |
+--------+-------------+
| 933737 | 84462331479 |
+--------+-------------+
enwikiquote
+--------+-------------+
| number | size |
+--------+-------------+
| 55186 | 98435989071 |
+--------+-------------+
eswikiquote
+--------+------------+
| number | size |
+--------+------------+
| 5712 | 7522618990 |
+--------+------------+
frwikiquote
+--------+-------------+
| number | size |
+--------+-------------+
| 7348 | 11151209748 |
+--------+-------------+
dewikiquote
+--------+------------+
| number | size |
+--------+------------+
| 4211 | 6149070638 |
+--------+------------+
enwikibooks
+--------+--------------+
| number | size |
+--------+--------------+
| 106405 | 133670795995 |
+--------+--------------+
eswikibooks
+--------+--------------+
| number | size |
+--------+--------------+
| 44309 | 122871671629 |
+--------+--------------+
frwikibooks
+--------+--------------+
| number | size |
+--------+--------------+
| 98843 | 248629243582 |
+--------+--------------+
dewikibooks
+--------+-------------+
| number | size |
+--------+-------------+
| 69669 | 54020348470 |
+--------+-------------+
All of them:
+---------+--------------+
| number | size |
+---------+--------------+
| 2021173 | 981218142389 |
+---------+--------------+
for wiki in enwiktionary eswiktionary frwiktionary dewiktionary enwikiquote eswikiquote frwikiquote dewikiquote enwikibooks eswikibooks frwikibooks dewikibooks; do echo $wiki; sql "${wiki}_p" "SELECT COUNT(img_name) AS number, SUM(img_size) AS size FROM image;"; echo; done
for wiki in enwiktionary eswiktionary frwiktionary dewiktionary enwikiquote eswikiquote frwikiquote dewikiquote enwikibooks eswikibooks frwikibooks dewikibooks; do echo $wiki; sql commonswiki_p "SELECT COUNT(img_name) AS number, SUM(img_size) AS size FROM image WHERE img_name IN (SELECT DISTINCT gil_to FROM globalimagelinks WHERE gil_wiki='$wiki')"; echo; done
SELECT COUNT(img_name) AS number, SUM(img_size) AS size FROM image WHERE img_name IN (SELECT DISTINCT gil_to FROM globalimagelinks WHERE gil_wiki IN ('enwiktionary', 'eswiktionary', 'frwiktionary', 'dewiktionary', 'enwikiquote', 'eswikiquote', 'frwikiquote', 'dewikiquote', 'enwikibooks', 'eswikibooks', 'frwikibooks', 'dewikibooks')) ;