Code Monkey home page Code Monkey logo

flaming-shame's Introduction

flaming-shame

Turning raster images into SVG files, one pixel at a time. Yes, really.

This particular repository is mostly up for archiving purposes, and to serve as a warning to others. If you actually like the idea and want to contribute, please go to https://github.com/meyerweb/px2svg, which is a semi-serious attempt to do this right. For whatever definition of “right” applies in this case.

What?

The PHP accepts a raster image (GIF, PNG, JPEG, that sort of thing) and creates an SVG image that recreates the raster image. It does this by drawing a filled rectangle for individual pixels in the image. In most cases, this is literally a 1-by-1 rectangle, but thanks to Amelia Bellamy-Royds, the code now draws a single rectangle for any vertical run of same-color pixels.

The script requires GD and curl.

Why?

Mostly, because of two things Chris Coyier said in his talk “The Wonderful World of SVG”.

The first was that you shouldn’t use SVG For something like a photo, because it would end up being way larger than a raster-format version of the same image. Sure, makes sense.

The second was that gzip, which pretty much every web server supports, worked by compressing similar runs of text, and that’s why SVGs are so compressable.

The two collided in my brain, and I thought: since a rectangle-per-pixel SVG would be highly repetitive, might the gzipped version actually be smaller than the raster image?

So I decided to find out.

Who?

Eric Meyer, sometime CSS guy. Eric A. Meyer if you’re nasty.

Chris Coyier, as mentioned, and Steve Champeon, both provided inspiration. Why Steve? Because I believe Steve did something very similar with divs, way back in the day. And even if he didn’t, he inspired me in a lot of other ways and deserves credit. I’m really sorry it came in this context, Steve.

Amelia Bellamy-Royds, sometime SVG gal, added the check for runs of constant color, alpha transparency support, and made the output a valid, responsive SVG file. Because she refused to accept that an SVG could be a less optimal image file format than a Windows .bmp bitmap file.

When?

I wrote the code in mid-May 2015, very shortly after hearing Chris’ talk at An Event Apart Boston. It was pushed to GitHub in early June 2015, causing a minor flurry of interest. Further bulletins as events warrant.

Seriously, why?

That really is why. Welcome to my brain.

flaming-shame's People

Contributors

meyerweb avatar ameliabr avatar robincafolla avatar mdmcginn avatar

Watchers

James Cloos avatar Alastair Kitchen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.