Skip export of full transparent tiles (map tiles)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
cub
Posts: 4
Joined: 2013-11-15T03:42:31-07:00
Authentication code: 6789

Skip export of full transparent tiles (map tiles)

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
cub
Posts: 4
Joined: 2013-11-15T03:42:31-07:00
Authentication code: 6789

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

Post 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 ?
cub
Posts: 4
Joined: 2013-11-15T03:42:31-07:00
Authentication code: 6789

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

Post 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 ;)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
cub
Posts: 4
Joined: 2013-11-15T03:42:31-07:00
Authentication code: 6789

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

Post by cub »

snibgo wrote:Unless you are using VARG later, you don't need it.
True ^^'
Thanks for your help/suggest snibgo !
Post Reply