Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Automatically extract sub-images from an image (or from HTML/CSS).
Python C Shell
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
docs
example
lib
.gitignore
AUTHORS.txt
LICENSE.txt
README.markdown
image-nuggets-util.c
image-nuggets-util.h
image-nuggets.c
image-nuggets.h
image_nuggets.py
image_nuggets_util.py
make.sh

README.markdown

Introduction

image-nuggets extracts sub-images from an image (or from HTML/CSS).

If the input is HTML, image-nuggets will use first use webkit2png (included) to render the input image.

  • This requires Mac OS 10.5 or later. Cross-platform patches welcome.
  • It's a modern engine, so u can haz border-radius and other modern goodness.
  • This can be really useful, especially if you're writing a script to test zillions of shades of teal and orange.

For now, image-nuggets uses this and only this nugget extraction method:

  1. Consider all pixels at the edge. Assert that they have the same color and call that the background color.
  2. Crop the image as tightly as possible without cropping a non-background color.
  3. See which full-width horizontal lines contain only the background color and split the image on runs of k or more of those lines (k = 5).
  4. Crop each subimage as in (2).

Prereqs

  • gcc
  • ImageMagick (or an equivalent convert on your PATH)
  • Optional: OptiPNG — it'll be used iff (--to=png) and (--optipng-level=N (e.g. N=2))

Building / Installing

  • Build it: ./make.sh
  • Optionally install it: add this repo's bin/ to your PATH

Kicking the Tires

  • cd example; ./make-example.sh

Command-line tools

cat buttons.html | image-nuggets
                            --from=html         // or gif, png, ...
                            --to=png            // or gif, ...
                            --optipng-level=2   // 0-7. Optional. Use only if --to=png
                            --dest-prefix=...
                            landing/lorem.png
                            landing/lorem_hover.png
                            landing/lorem_active.png

image-nuggets is a Python script which wraps this C program:

cat foo.ppm | image-nuggets-c > ppms.chunks
  • PPM must be a P6
  • ppms.chunks: ''.join(('%d\n%s' % (len(ppm), ppm)) for ppm in subppms)
Something went wrong with that request. Please try again.