[OpenLayers-Dev] Add support for mixed mode image tile caches

Joe Franklin traderboy at yahoo.com
Thu Mar 10 10:25:16 EST 2011


Looking at the TMS, TileCache, WMTS classes (maybe others), the image extension is added to the url in the getURL function.  What if you want to use a mixed mode cache that uses both PNG and JPEG?  This option is useful for hi-res imagery caches that will be used as overlays.  The border tiles use PNG32 so you can use transparency for the image edges, the inner tiles use JPEG which don't require transparency.  The only change required for OpenLayers is to modify the getURL so it doesn't require a file extension.

Ex: http://myserver/tiles/0/0/0.png becomes http://myserver/tiles/0/0/0
Now the file 0 can be a PNG or a JPEG.

Here's part of what I posted at http://groups.google.com/group/mod-geocache:

Here's a simple solution to creating a multiple image format tile 
cache.  It works on a pre-seeded disk cache.  The idea is simple: 
replace all the png24 images with JPEG, leave the png32 images alone 
(or optionally run pngcrush on them), then remove the file extensions 
from all tiles so the client can access both without needing to know 
their format/extension.

Requires: ImageMagick and pngcrush (both available using yum) 
Run this in the root directory of your cached tile layer (ex: /tiles/ 
test2).  I'm sure it can be written more cleverly, but it seems to 
work.  It reduced the size of my cache 58% by using both png and 
jpegs. 


for file in `find . -name "*.png"`;do 
if [ -h $file ]; then 
        echo "Removing .png from symbolic link"; 
        filename=${file%.*}; 
        mv -f $file "$filename"; 
else 
        hasAlpha=`identify -verbose $file | grep Alpha`; 
        if [ "$hasAlpha" != "" ]; then 
                echo "Has alpha: $file"; 
                #run pngcrush to reduce the size of the png 
                pngcrush -q -rem allb -brute "$file" tmp_img_file.png; \ 
                mv -f tmp_img_file.png $file; \ 
                #remove the .png extension 
                filename=${file%.*}; 
                mv -f $file "$filename"; 
        else 
                echo "No alpha: $file"; 
                filename=${file%.*}; 
                convert "$filename.png" "$filename.jpg"; 
                #remove the .png file 
                rm -Rf $file 
                #remove the .jpg extension 
                mv -f "$filename.jpg" "$filename"; 
        fi; 
fi; 
done; 

ESRI's mixed mode image format for ArcGIS server where I swiped the idea:
(See pic on page 12 of http://proceedings.esri.com/library/userconf/cahinvrug10/papers/tech-sessions/arcgis_server_road_ahead.pdf) 



      


More information about the Dev mailing list