I've folders containing png images of map tiles to be overlayed on google maps, created using QTiles plugin in QGIS. I want to remove the white background of all the tiles so that base map is properly visible. Names of folders and files should not be changed as they represent zoom levels and position of the tiles. Can you please suggest how this can be done? Thanks
To do this you will have to manually edit 1 image. In doing so you will set up a new action (assuming you have Photoshop).
Take your first image and open it in Photoshop.
From there, if the actions panel is not visible, click at the top "window" > "Actions"
At the bottom of the actions panel select "Create New Action" Name the Action I named mine "Remove White BG". Then Hit Record. See below:
Now it is recording (You can tell by the red circle in the actions panel).
I had some trouble opening PNG's so the first step in your action should be to convert to RGB (In my case this makes the PNG editable).
Then Click the lock located on your current layer to unlock it.
From there click "Select" > "Color Range" Then using the eye dropper select the white background. (Depending on the quality/contrast of the image this should be fairly simple, but could require some finesse to get the entire background selected). I chose a black and white image (and increased the fuzziness to 200% to select any loose "off-white" pixels). See below:
The result is this:
Now your Action is ready to be utilized in the batching process.
Go to "File" > "Automate" > "Batch"
At the top of the window select the action you just made.
Choose your start folder (the folder your PNG's are located in).
Choose a Destination folder (this can temporary, so you can eventually replace your current PNG's)
In the File Naming Section. make sure the first line says "document name" and the second line says "extension" (this will ensure your naming stays the same).
Edit any other settings that may interest you and hit OK.
Like I said earlier this will work very well for images with a plain background that contrasts the foreground, the more complex the image the harder it will be to batch them all. Good luck.