How do I write a script to automatically optimize all the PNGs in my MediaWiki images directory?

Josh Pinto

I have MediaWiki 1.25.2 installed on my 64-bit Debian 8.1 VirtualBox machine and I'd like to be able to upload the images/ directory from this installation to my DropBox. Being a cheapskate I'm trying to minimize the size of this images directory by optimizing the PNGs found therein with optipng, so that I don't end up with a DropBox that's so full that I need to pay for more storage. My Wiki has at the moment 182 PNGs that I have uploaded to it (along with well over a hundred others that are thumbnails of these original PNGs and of the SVGs I have on my Wiki), so running optipng -o7 <filename> on each of these files manually will be very tedious.

Hence I am here asking, how I might write a bash script that will automatically do this for me. Now I know some pieces of the puzzle of how to do this, like I know that the find program can generate lists of files with a specified file extension in a specified location (e.g., running sudo find . -type f -name "*.png" from the images/ directory which for me is at /var/lib/mediawiki/images will list all the PNGs therein), but I don't know how to use this program to create a text file containing all the file names relative to this directory (e.g., f/f1/Frugalware_Linux_screenshot.png). I also don't know how to get optipng to optimize PNGs listed in a text file.

Marco

Try:

for i in `find . -type f -name "*.png"`
do
  optipng -o7 "$i"
done

Did not test it but it should work like that. If you need to test it then you might change the line optipng -o7 $i with echo $i to see if you get the correct file.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I write a script to automatically compile and install all Moksha modules?

From Dev

How do i write a shell script so that when i compile my c++ program it will put the binary into the Binary Directory

From Dev

How do I get my shell script to automatically accept prompts?

From Dev

How can I find all the unused and uncategorized pages and images in MediaWiki?

From Dev

How do i run python script on all files in a directory?

From Dev

How do i run python script on all files in a directory?

From Dev

How do I optimize my query in MySQL?

From Dev

How do I optimize my query in MySQL?

From Dev

How do I optimize my MongoDB Database?

From Dev

How do I automatically sync all videos I record with my android phone to my desktop?

From Dev

How do I get all images within Wordpress Uploads directory, then display all?

From Dev

How can I write a bash script to search all files in current directory for multiple strings?

From Dev

How do I convert a directory of images into a .gz?

From Dev

How do I convert a directory of images into a .gz?

From Dev

How do I search for visually duplicated images from my directory and move them?

From Dev

How do I write a batch script that iterates through all png files in all subfolders and does an action?

From Dev

I want my script to give popup automatically after 3 hours? how can do it?

From Dev

How do I write a PowerShell alias that changes directory and lists all files and folders?

From Dev

How do I optimize* this?

From Dev

My Greasemonkey script starts a sequence of images loading. How do I stop it when desired?

From Dev

How do I build in images to my app

From Dev

Does gcc automatically use -j4? Is there anything I can do to optimize my compilation?

From Dev

How do I optimize my ul navigation for mobile

From Dev

How do I optimize my RAND() function for large tables?

From Dev

How do I display all of the images from my Firebase Storage in React Native without needing image names?

From Dev

How do I get the output of a cron script run from my home directory?

From Dev

How do I write a script that runs on startup?

From Dev

How do I encrypt my /tmp directory?

From Dev

How do I encrypt my /tmp directory?

Related Related

  1. 1

    How do I write a script to automatically compile and install all Moksha modules?

  2. 2

    How do i write a shell script so that when i compile my c++ program it will put the binary into the Binary Directory

  3. 3

    How do I get my shell script to automatically accept prompts?

  4. 4

    How can I find all the unused and uncategorized pages and images in MediaWiki?

  5. 5

    How do i run python script on all files in a directory?

  6. 6

    How do i run python script on all files in a directory?

  7. 7

    How do I optimize my query in MySQL?

  8. 8

    How do I optimize my query in MySQL?

  9. 9

    How do I optimize my MongoDB Database?

  10. 10

    How do I automatically sync all videos I record with my android phone to my desktop?

  11. 11

    How do I get all images within Wordpress Uploads directory, then display all?

  12. 12

    How can I write a bash script to search all files in current directory for multiple strings?

  13. 13

    How do I convert a directory of images into a .gz?

  14. 14

    How do I convert a directory of images into a .gz?

  15. 15

    How do I search for visually duplicated images from my directory and move them?

  16. 16

    How do I write a batch script that iterates through all png files in all subfolders and does an action?

  17. 17

    I want my script to give popup automatically after 3 hours? how can do it?

  18. 18

    How do I write a PowerShell alias that changes directory and lists all files and folders?

  19. 19

    How do I optimize* this?

  20. 20

    My Greasemonkey script starts a sequence of images loading. How do I stop it when desired?

  21. 21

    How do I build in images to my app

  22. 22

    Does gcc automatically use -j4? Is there anything I can do to optimize my compilation?

  23. 23

    How do I optimize my ul navigation for mobile

  24. 24

    How do I optimize my RAND() function for large tables?

  25. 25

    How do I display all of the images from my Firebase Storage in React Native without needing image names?

  26. 26

    How do I get the output of a cron script run from my home directory?

  27. 27

    How do I write a script that runs on startup?

  28. 28

    How do I encrypt my /tmp directory?

  29. 29

    How do I encrypt my /tmp directory?

HotTag

Archive