Using pngnq with recursion into directories

369 views
Skip to first unread message

br8kwall

unread,
Apr 6, 2009, 10:59:22 PM4/6/09
to MapTiler User Group
Does anyone have an incantation that facilitates using pngnq
http://pngnq.sourceforge.net/ ) with the myriad directories generated
by maptiler?

Best solution would allow a single command to be run at the top of the
directory structure and then pngnq would just recurse into the
subdirectories and replace the maptiler PNGs with the smaller
versions. Of course the best solution would be to also pipe it through
pngcrush I guess.

I'm totally enjoying maptiler. I find myself just making online maps
for the fun of it now.

fame

unread,
Apr 7, 2009, 3:56:08 PM4/7/09
to MapTiler User Group
Hi,
I used the for command:

placing pngnq somewhere reported in the PATH enviroment variable, you
can go to the top directory then digit:

for /r %i in (*.png) do pngnq.exe %i

the parameter /r scan the subdirectory recursively and in this case
consider only files *.png
%i is the variable

Bye

Amedeo Fadini



John Zastrow

unread,
Apr 11, 2009, 3:11:18 PM4/11/09
to mapt...@googlegroups.com
Nice. Trouble is I need the same for linux instead. Do you have any thoughts for Linux? My primitive BASH scripting ability and some Googling does not find an equivalent for the /r % approach in DOS.

John Zastrow

unread,
Apr 11, 2009, 3:20:29 PM4/11/09
to mapt...@googlegroups.com
For example, this is not doing the job.

#!/bin/sh
for dir in */
do cd $dir && [whatever]
done

John Zastrow

unread,
Apr 11, 2009, 4:03:15 PM4/11/09
to mapt...@googlegroups.com
I'm getting closer as I just remembered find -exec. This does recurse into subdirectories.

Now I just need to recurse and rename the files, so I've got this so far. But rename will not recurse

find . -name '*.png' -exec pngnq {} \;
rename -v 's/\.-nq8.png$/\.png/' *.-nq8.png
 (use rename -n to just test the operation)

John Zastrow

unread,
Apr 14, 2009, 10:41:18 PM4/14/09
to mapt...@googlegroups.com
Well, I was hoping for something more elegant, but this works as a solution to pass all of the images made by maptiler through pngnq to optimize them. I'm using the NOAA raster nav charts and pngnq shaves over half of the file size off without losing quality.

I'm doing this in linux right now and the following commands issues in order will process the entire directory tree.

# Verbosely quantize all .png files in this directory and below using default values
find . -name '*.png' -exec pngnq -v -e.png2 {} \;

# Backup the original .png files to allow renaming. Delete these later
find . -name '*.png' -exec rename -v 's/\.png$/\.png-bak/' {} \;

# Rename the quantized images to the expected name
find . -name '*.png2' -exec rename -v 's/\.png2$/\.png/' {} \;

fame

unread,
Apr 24, 2009, 11:17:19 AM4/24/09
to MapTiler User Group
I used the same three-steps process in windows enviroment, I don't
know if there is th choice to do this in one step only.

Amedeo

fame

unread,
May 28, 2009, 10:10:49 AM5/28/09
to MapTiler User Group
In case it will be helpful... this is the batch script I've made to
run on windows enviroment

-----
title Ottimizza immagini
@echo off
REM ******************************************
REM Batch to process an image tile with pngnq.exe (the exe file anthe
batch file must be on the same directory, the root of the pyramid)
REM ottimizza le immagini png con trasparenza - Amedeo Fadini
Kibernetes srl
REM www.kibernetes.it afa...@kibernetes-tv.it maggio 2009
REM *******************************************

echo change extension to .pn
echo.
REM this line rename images png to pn
for /r %%i in (*.png) do rename "%%i" *.pn
echo.

REM this line select files *.pn optimize, and save with other name
REM the suffix is only "g" (to make correct extension)

echooptimizing images .pn and saving as png
for /r %%p in (*.pn) do pngnq.exe -f -e g "%%p"
echo.

REM qui chiedo se cancellare i file originali (sarebbe meglio
controllare se son venuti bene prima)
set /p canc=do you want to delete .pn files (y/n)?

if %canc% ==y (goto :delete) else (echo you chose to don't delete *.pn
files & goto :fine)


:delete
for /r %%d in (*.pn) do del "%%d"

pause

:fine
echo ***********************
echo end

pause

srvm...@gmail.com

unread,
Jun 5, 2009, 5:03:56 AM6/5/09
to MapTiler User Group
Thanks, this script is an important time-saving.

Then, I write some small changes that are necessary to run the script
on a Windows 2000:

line 14:
for /r %%i in (*.png) do rename "%%i" *.pn

replaced by:

for /r %i in (*.png) do rename "%i" *.pn


line 21:

for /r %%p in (*.pn) do pngnq.exe -f -e g "%%p"

replaced by:

for /r %p in (*.pn) do pngnq.exe -f -e g "%p"


line 32:

for /r %%d in (*.pn) do del "%%d"

replaced by:

for /r %d in (*.pn) do del "%d"



On May 28, 4:10 pm, fame <ame...@gmail.com> wrote:
> In case it will be helpful... this is the batch script I've made to
> run on windows enviroment
>
> -----
> title Ottimizza immagini
> @echo off
> REM ******************************************
> REM Batch to process an image tile with pngnq.exe (the exe file anthe
> batch file must be on the same directory, the root of the pyramid)
> REM ottimizza le immagini png con trasparenza - Amedeo Fadini
> Kibernetes srl
> REMwww.kibernetes.itafad...@kibernetes-tv.it maggio 2009

Gustavo

unread,
Mar 29, 2017, 4:16:37 PM3/29/17
to MapTiler Community
Hello Amedeo
Back in 2010 I use your script with pngnq0_5.exe
Now I am trying to run it but apparently some dlls or another issues prevent me to finish the job.
Maybe I am using an old version of pngnq on my windows 8.
What I need is to apply the image quantization to an entire tree of files produced by maptiler.
Any ideas?

Klokan Technologies GmbH

unread,
Mar 29, 2017, 7:47:36 PM3/29/17
to mapt...@googlegroups.com
If you use the latest MapTiler (http://www.maptiler.com/) the tiles are already very well optimized if you choose PNG8 format (the default).

There is no need to run pngnq anymore...

Best regards,

Petr

--
Klokan Technologies GmbH
Hofnerstrasse 96, Unterägeri 6314, Switzerland
Tel: +41 (0)41 511 26 12

--
You received this message because you are subscribed to the Google Groups "MapTiler Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maptiler+unsubscribe@googlegroups.com.
To post to this group, send email to mapt...@googlegroups.com.
Visit this group at https://groups.google.com/group/maptiler.
For more options, visit https://groups.google.com/d/optout.

Gustavo Henriquez

unread,
Mar 29, 2017, 9:28:16 PM3/29/17
to mapt...@googlegroups.com
You are right, however I am using an old version of Maptiler (1.0 beta 2 without watermark) that I download in 2010  and I need the optimization. 
I would like to test the Google Earth Overlay with a satellite image of 21000 pixels swath


Gustavo Henríquez
CONIDA
(Address) Felipe Villaran 1069, Lima27, Peru
(Phone) 511-441 9081 Ext.124

--
You received this message because you are subscribed to a topic in the Google Groups "MapTiler Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/maptiler/CzPi7IPUTq8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to maptiler+unsubscribe@googlegroups.com.

Klokan Technologies GmbH

unread,
Mar 31, 2017, 7:16:59 AM3/31/17
to mapt...@googlegroups.com
Dear Gustavo, 

I would like to recommend you to purchase the latest version at http://www.maptiler.com/pricing/, so you can enjoy all features we have been developing for years. You can also download the FREE version there and see if it meets your needs, of course.

Sincerely yours,
KlokanTech Team

--
Klokan Technologies GmbH
Hofnerstrasse 96, Unterägeri 6314, Switzerland
Tel: +41 (0)41 511 26 12

Reply all
Reply to author
Forward
0 new messages