School of Computing. Dublin City University.
Online coding site: Ancient Brain
coders JavaScript worlds
totalimg file.htmlAdd up total size of all embedded images in this HTML file.
To test it we will run it on pages in my test suite:<img src="filename"> <img .... src="filename"> <img width=... src="filename"> <img style=... src="filename"> <img .... src="filename" .... >
cd /users/tutors/mhumphrysdculab/share/testsuite
$ cd /users/tutors/mhumphrysdculab/share/testsuite/Cashel $ totalimg george.html
You should now just have a list of embedded local images, like this:
$ cd /users/tutors/mhumphrysdculab/share/testsuite/Cashel $ totalimg george.html <img border=0 src="../Icons/pdf.gif"> <img border=0 src="../Icons/pdf.gif"> <img src="Bitmaps/ric.crop.2.jpg"> <img src="../Icons/me.gif"> <img width="98%" src="../Kickham/08.Mullinahone/SA400010.small.JPG"> <img width="98%" src="../Kickham/08.Mullinahone/SA400028.small.JPG"> <img width="95%" src="07.Carlow.Stn/SA400069.lores.jpg"> <img border=1 width="95%" src="07.Carlow.Stn/SA400070.lores.adjust.jpg"> |
Pipe the above into further commands to extract the image file names.
$ cd /users/tutors/mhumphrysdculab/share/testsuite/Cashel $ totalimg george.html ../Icons/pdf.gif ../Icons/pdf.gif Bitmaps/ric.crop.2.jpg ../Icons/me.gif ../Kickham/08.Mullinahone/SA400010.small.JPG ../Kickham/08.Mullinahone/SA400028.small.JPG 07.Carlow.Stn/SA400069.lores.jpg 07.Carlow.Stn/SA400070.lores.adjust.jpg |
while read file do if test -f $file then ls -l $file fi done |
$ cd /users/tutors/mhumphrysdculab/share/testsuite/Cashel $ totalimg george.html -rwxr-xr-x 1 mhumphrysdculab tutors 426 Sep 17 2015 ../Icons/pdf.gif -rwxr-xr-x 1 mhumphrysdculab tutors 426 Sep 17 2015 ../Icons/pdf.gif -rwxr-xr-x 1 mhumphrysdculab tutors 39139 Sep 17 2015 Bitmaps/ric.crop.2.jpg -rwxr-xr-x 1 mhumphrysdculab tutors 1005 Sep 17 2015 ../Icons/me.gif -rwxr-xr-x 1 mhumphrysdculab tutors 339817 Sep 17 2015 07.Carlow.Stn/SA400069.lores.jpg -rwxr-xr-x 1 mhumphrysdculab tutors 190968 Sep 17 2015 07.Carlow.Stn/SA400070.lores.adjust.jpg |
stat --printf="%s" $file echo
$ cd /users/tutors/mhumphrysdculab/share/testsuite/Cashel $ totalimg george.html 426 426 39139 1005 339817 190968 |
TOTAL=0 while read size do TOTAL=`expr $TOTAL + $size` done echo "$TOTAL" |
$ cd /users/tutors/mhumphrysdculab/share/testsuite/Cashel $ totalimg george.html 571781 $ totalimg bushfield.html 3274461 $ cd /users/tutors/mhumphrysdculab/share/testsuite/ORahilly $ totalimg the.orahilly.note.html 2515730 $ totalimg ballylongford.html 1654649 |
Imagine using this script to search thousands of pages for the most overloaded pages.