Page 1 of 1

Skip export of full transparent tiles (map tiles)

Posted: 2013-11-15T03:58:33-07:00
by cub
Hi,

I'm using ImageMagick for exporting tiles layer for map (like openstreetmap). It works well :

Code: Select all

convert "zoom12.png" -crop 256x256 ^
-set filename:tile "%%[fx:page.x/256+2064]_%%[fx:page.y/256+1401]" ^
+repage +adjoin "%%[filename:tile].png"
But sometimes, my image ('zoom12.png' in my exemple) has large 'empty' zone (full transparent). So when the crop export do his job, it export a lots off empty tiles ( like exporting 1k tiles of rgba(0,0,0,0)). It is not a big problem but is there a way to skip exporting them (time saving export + ftp transfert) ? Or a way to have a checker/cleaner to delete this empty tiles ?

Anyway thanks to ImageMagick project/community.

@ImageMagick-6.8.7-5 Windows

Re: Skip export of full transparent tiles (map tiles)

Posted: 2013-11-15T04:52:16-07:00
by snibgo
I don't think your command can be modified to prevent the saving of empty tiles.

Another command can be written to delete empty files: just find the maximum value of A (Alpha). If this is zero, the image is entirely transparent.

EDIT: It turns out there may be a bug in this area. See viewtopic.php?f=3&t=24461

Re: Skip export of full transparent tiles (map tiles)

Posted: 2013-11-15T06:26:08-07:00
by cub
Hmm.. "2091_1429.png" is a empty tile as I explained

I tried :

Code: Select all

identify -format "%[fx:maxima.a]" 2091_1429.png
Return me 1

And if I do a verbose it log me a correct min&max 0 alpha :

Code: Select all

identify -verbose 2091_1429.png
Image: 2091_1429.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 256x256+0+0
  Resolution: 393.7x393.7
  Print size: 0.650241x0.650241
  Units: PixelsPerCentimeter
  Type: PaletteAlpha
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8/1-bit
  Channel depth:
    red: 1-bit
    green: 1-bit
    blue: 1-bit
    alpha: 1-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Green:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Blue:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Alpha:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
Wrong synthax of identify -format or bug ?

Re: Skip export of full transparent tiles (map tiles)

Posted: 2013-11-15T07:26:03-07:00
by cub
Ok I wrote a cleaner :

Code: Select all

SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%F IN (*.png) DO (
FOR /f %%i in ('D:\im\identify -format "%%[fx:maxima.o]" "%%F"') DO (
set VARG=%%i
IF [!VARG!]==[0] DEL %%F
)
)
The first loop is to parse all png
The second to save the result of the identify (need SETLOCAL ENABLEDELAYEDEXPANSION for non compiled/dynamic var)

Note I use %[fx:maxima.o] that return 'correct' value (for extrem value 0-1, viewtopic.php?f=3&t=24461) and not %[fx:maxima.a].

If someone has a better idea ;)

Re: Skip export of full transparent tiles (map tiles)

Posted: 2013-11-15T13:42:15-07:00
by snibgo
There is currently a bug in both "%[fx:maxima.a]" and "%[fx:maxima.o]".

In your cleaner:

Code: Select all

set VARG=%%i
IF [!VARG!]==[0] DEL %%F
why not:

Code: Select all

IF [%%i]==[0] DEL %%F
Unless you are using VARG later, you don't need it.

Re: Skip export of full transparent tiles (map tiles)

Posted: 2013-11-19T02:05:11-07:00
by cub
snibgo wrote:Unless you are using VARG later, you don't need it.
True ^^'
Thanks for your help/suggest snibgo !