A Python script that generates high-quality 9-patch PNG files with circular shapes, perfect for Android UI development and other applications requiring scalable rounded rectangles.
- ✨ High-quality antialiased output with 4x supersampling
- 🎯 Two modes: filled circles or border-only circles
- 📱 Multi-resolution support: automatically generates FHD and HD variants
- 🔧 Proper 9-patch markers for fixed corner radius behavior
- 🎨 Clean white shapes on transparent backgrounds
pip install Pillow numpygit clone https://github.com/rak0njac/ninepatch-generator.git
cd ninepatch-generator# Generate filled circle with radius 50
python ninepatch_generator.py 50
# Generate border circle with radius 50 and border width 5
python ninepatch_generator.py 50 --border 5# Filled circles
python ninepatch_generator.py 24 # Small button
python ninepatch_generator.py 48 # Medium button
python ninepatch_generator.py 72 # Large button
# Border circles
python ninepatch_generator.py 24 --border 2 # Thin border
python ninepatch_generator.py 48 --border 4 # Medium border
python ninepatch_generator.py 72 --border 6 # Thick borderThe script generates files in two directories:
fhd/- Full HD resolution (original size)hd/- HD resolution (66.67% of original size)
- Filled circles:
fill_{radius}.9.png - Border circles:
border_{radius}.9.png
fhd/
├── fill_24.9.png
├── fill_48.9.png
├── border_24.9.png
└── border_48.9.png
hd/
├── fill_24.9.png # Actually 16px radius
├── fill_48.9.png # Actually 32px radius
├── border_24.9.png # Actually 16px radius
└── border_48.9.png # Actually 32px radius
The generated files include proper 9-patch markers:
- Stretch markers: 2 pixels on top and left edges for minimal stretching
- No content markers: Clean output without padding constraints
- Fixed corner radius: Maintains circular corners when stretched
The script uses 4x supersampling for smooth edges:
- Renders at 4x resolution
- Applies high-quality downsampling
- Results in professional anti-aliased output
HD variants are generated by scaling the radius rather than the final image:
- Better quality: Native rendering at each resolution
- Consistent proportions: Proper 9-patch marker positioning
- Sharp results: No additional resampling artifacts
positional arguments:
radius Radius of the circle in pixels
optional arguments:
-h, --help Show help message
--border BORDER Border width in pixels (creates border-only circle)
-o, --output Output filename (ignored - uses automatic naming)
- Android app UI components
- Web UI rounded buttons and containers
- Game UI elements
- Any application requiring scalable rounded rectangles
MIT License - feel free to use in your projects!
Issues and pull requests welcome! Please feel free to suggest improvements or report bugs.