Tag Archive: gd


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.

View full article »

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).

View full article »

Map of Canada chart with province value colour coding.

This is PHP class I developed for work when I needed a Canada-specific map chart in some reporting tools I was creating. Obviously Google’s Map Charts API would’ve been my first choice, but it didn’t support Canada as it’s zoom level for reporting province-based data sets.

This is where I sat down, thought about a quick and dirty way to create this chart and went to work. I was able to create a chart as show on the right, with full control of output dimensions and colours.

Before I jump right into the full code, I want give a brief explanation of some of the techniques I used to accomplish this task.

View full article »

Generating MP3 waveforms with PHP

UPDATE: After some great comments, I have optimized the performance of this script and made some brief commentary available here. I have also updated any source code links below to the new github project page.

I don’t quite know what gave me the desire to ever generate audio (specifically MP3) waveforms with PHP — it’s not something I’ll likely ever use — but after doing some research and coming up a bit short I decided to make it happen.

Waveform generated using Dancing With Paris' "(Boardwalk)" MP3.

A few days of Googling, I did come up with a couple solutions but none seemed to really produce the results I wanted. All I was looking to generate was a simple waveform like that in Cubase or other recording software. I don’t need axis labels or left/right audio splits, just a simple mono waveform from an MP3. I also didn’t want to go through hundreds of audio files and convert them into WAV files just to do this — if I was going to do this as an experiment, I wanted it on the fly. I did come across some interesting links though:

View full article »

Powered by WordPress | Theme: Motion by 85ideas.