In my last post I was looking for a way to give simple images transparent backgrounds. I noted that PHP GD’s imagefill function wasn’t quite what I was looking for as it only replaced exact colours based on your starting image coordinates. I gave this problem some brief thought and came up with a slightly better algorithm using colour distance calculation and simple recursion.
Archive for November, 2010
I needed a quick and dirty script (that I took a few minutes to clean up and throw together in a class) that can take a basic JPEG and turn it into a transparent PNG around the edges. I called it “Transparentize” — only because I couldn’t find any proper term for this.
I looked into PHP GD library’s imagefill function but it wasn’t quite giving me the results I needed. It only filled for exact colours, and in a JPEG with millions of colours, there are a number of variations of what the average set of eyes perceives as “white.” I need something where a threshold could be specified and find the edges of an image on a high contract background (for example, a basic black square on a white background).
