• Stars
    star
    257
  • Rank 158,728 (Top 4 %)
  • Language
    C
  • License
    Other
  • Created over 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Read in a gradient from a png file and spit out CSS for it

pngtocss takes in a png file with a gradient in it and spits out the necessary CSS to draw that gradient.

It only works with:

  • 24 bit PNGs
  • only linear gradients
  • horizontal gradients
  • vertical gradients
  • diagonal gradients
  • multi-colour support only for horizontal and vertical

It does not support:

  • radial gradients
  • angular gradients (except for perfect diagonal)
  • more than 2 colours on diagonal gradients

Code

See the examples/ directory for all the pngs that I've tested this with. Feel free to submit your own (keep them small).

See the src/ directory for the source code.

It's written in C, and uses libpng 1.6.25 and zlib 1.2.8. You'll need both of those to compile it. Also, I wrote it on MacOSX, so I installed the libraries using ports. You may need to play with the Makefile if you're using a different OS. Sorry, I don't have the time to test, but if you submit a pull request, I'll merge it.

License:

BSD Licensed v2.0

Copyright:

© Philip Tellis -- [email protected] -- http://bluesmoon.info/

Credits:

Everything I know about reading a PNG I got from Chapter 13 of the libpng book: http://www.libpng.org/pub/png/book/chapter13.html

The CSS gradient syntax came from these wonderful sites:

History:

Nicole tweeted about the absence of a tool to convert images to gradients:

Screenshot of Nicole's tweet

I realised that I knew neither what CSS gradients were, nor how to read a PNG file, so figured that this was a good opportunity to learn both at once. I decided to write it in C because I hadn't written C code in a very long time.

Patches welcome.

Things I learnt

  • The average of two colours will be closer to one than to the other.

Discussion

Talk about pngtocss on the discussion page

More Repositories

1

node-faststats

Quickly calculate statistics of a running stream of data
JavaScript
192
star
2

yui-flot

Port of Flot to YUI
JavaScript
30
star
3

netperf-js

A Bandwidth tester in Javascript... but please use boomerang instead, I'm moving development there
JavaScript
12
star
4

node-line-input-stream

Convert a Node.JS Readable Stream into a Line Buffered Input Stream
11
star
5

404kids

Put missing kids on your 404 page
PHP
9
star
6

talks

My public talks
TeX
9
star
7

node-prettydate

Pretty date formatting for Node.JS
JavaScript
8
star
8

CurlHTTP.jl

CurlHTTP is a wrapper around LibCURL that provides a more Julia like interface to doing HTTP via Curl.
Julia
7
star
9

html-template-javascript

Project to port HTML::Template to javascript
JavaScript
6
star
10

data-science-career

A roadmap for Data Science careers
5
star
11

icici-direct-crawler

Automate some of the things I do with ICICI Direct
Python
3
star
12

bluesmoon.github.com

bluesmoon's home on github
3
star
13

make-icicidirect-better

A bunch of greasemonkey scripts to make ICICIDirect a little better.
3
star
14

MethodInspector.jl

Julia package to inspect the names and types of method arguments
Julia
2
star
15

httptype

Find out which HTTP server runs on a given host/port
2
star
16

boomerang-sample-plugin

Sample plugin for boomerang with steps to create it. See https://github.com/bluesmoon/boomerang for more plugins.
JavaScript
2
star
17

node-ua-parser

UserAgent Parser for NodeJS
1
star
18

4.01-strict

Source code for the 4.01 Strict comic strip
1
star
19

measures

On screen measures for common units
1
star
20

config

Config files I use
Shell
1
star