September 12

Generating an Image's Color Scheme Using Imagick

UPDATE:It seems that the TinyMCE environment I used to edit this post stripped the <pre> I used to wrap the code. Everything should be fine now though!

When I got the idea behing TwitColors the first question I asked myself was "What's the best way to get the colors out of an image?". And since it was the main component for the whole application and it analyzed about 60 full-size images it also had to be fast, since this was only the beginning of the whole analytic process that is behind TwitColors.

This being said I almost instantly eliminated (or `hated` to be more exact) the idea of iterating through all the image's pixels and finding out their color and then using a math formula to "merge" the colors. It could be done but it would take too much time that the app doesn't have. After forgeting about this approach I remembered seeing an interesting function in the Imagick library. That function is Imagick::quantizeImage(). And it does exactly what I neede it to do: it "cuts" the number of colors inside an image to the number you give it. And I wanted 10.

Without any more hustle I'm going to present you with the code I used to extract 10 unique colors from an image:

$im=new Imagick($image);
$im->quantizeImage( 10, Imagick::COLORSPACE_RGB, 0, false, false );
$im->uniqueImageColors();
$it=$im->getPixelIterator();
foreach ($it as $row=>$pixels)
	foreach ($pixels as $column=>$pixel)
		{
		$rgba=$pixel->getColor();
		}

Basically everything it does is to load the image as a new Imagick object, reduce the number of colors in the image to 10 RGB colors (using the Imagick::quantizeImage() function I was talking about earlier), delete all unrequired pixels from the image keeping only one pixel for any unique color (that is what Imagick::uniqueImageColors() does). Up until this point the full-size image has been converted to a tiny image that is 10px wide and 1px high. Now everything that remains to be done is to get the colors of those pixels in a PHP readable format - that is either and HEX value or an RGB array. This is also done with Imagick by creating a new PixelIterator object using the Imagick::getPixelIterator() function and then using a simple loop to go through the matrix of pixels and getting their color using the ImagickPixel::getColor() function that returns an RGBA (red, green, blue, alpha) array of the color.

That's it. Now you can easily get the color scheme of any image without needing any specialized software and straight from your PHP scripts.

03:09 PM | 0 Comments | Tags: , , , , , ,
September 11

DropBox + iDrive = <3

Lately I found myself more and more concerned about the safety (as in protection against disaster) of my data. I am not really sure if it's just a temporary thing before I go on and cancel all those services but we shall see.

So..what did I do? Simple...

I just went on and bought subscriptions to two differrent online storage services: DropBox and iDrive. And started using and loving them both right away.

I am right now backing up all my laptops hard drive using iDrive, which gives you 150GB of online storage as well as a quite nicely done piece of software for scheduling backups, recovering data and the like. Everything seems fine until now.

While I'm using iDrive for my whole-drive backup I also needed a service that would have more `sharing` features and would give me the simple ability to sync a folder across more computers while also allowing me to access those files from any other computer through an online interface. This is where DropBox comes into play and it allows me to do just that!

Now I have a folder called "My Dropbox" on both my laptop and work PC and they are always in sync! Another nice feature of DropBox is that it also has some backup capabilities, like file versioning and deleted files recovery.

Oh! And being a developer I couldn't not notice that DropBox has an API. I might give it a spin when I get the chance! ;-)

08:57 PM | 1 Comment | Tags: , , , ,
August 23

TwitColors.com

UPDATE: Great news for designers! TwitColors now allows you to download a certain user's color scheme in .ACO format. You can find the download link below the user's color listing.

A few days ago I made a blog post stating that I'm working on a bunch of projects that I really hope to get online asap. Well, I have a good news for both you and me. One of them is online.

The project I'm talking about now is TwitColors, a new way to explore Twitter from a colorful perspective.

It basically analyzes the Twitter profile image of a given person and brakes it to up to 10 unique colors which are then matched to a database of thousands of already discovered colors and Twitter users and generates it's color scheme as well as tops for the most and least used colors in profile images among different tweeps.

Example color schemes: http://twitcolors.com/encu, http://twitcolors.com/loic

 

But enough with the talk. Go and check it out at http://twitcolors.com

 

04:33 PM | 0 Comments | Tags: , , ,
August 19

Projects

When I said there is a lot coming I wasn't kidding. And I say it again: I've got a lot coming up in a short while.

Aside from my work I've been developing 4 other personal projects. This projects are in their early age but I am almost sure at least one will see the day light quite soon.

I can't tell you much about these four projects but I can tell you that they're pretty different. They range from G.A. [ as in General Audience ] to D.O. [ as in Developer-Only].

This being said I hope you can now understand why I will not be able to keep the interesting posts coming around here, since I'm focusing my efforts on raising these for babies. :-)

01:39 AM | 0 Comments | Tags: ,
August 17

Chyrp. Why?

Until two days ago when I thought about a blog I thought about WordPress (no, not because I didn't know any other alternatives but because I considered it to be the best). But every time I installed WordPress I found myself installing a whole shitload of plugins and widgets and then realizing that I do not need them and removing them.

Leaving the time I was losing doing so aside, the fact is that WordPress is quite poorly written. Having both structural and object-oriented code, huge classes that you do not actually need and the like. It was quite a memory hog.

If I used all that features I would have gladly gone with WordPress once again. But then I discovered Chyrp. I would call it a barebone blog cms. Why? Because when you first install it, it's quite blind. It has a few (and just a few) features and that's all. But that was almost everything I needed.

Installing it is a breeze. You might want to enable a few modules to give it a little more functionality but that's all. You'll end up with having a good blogging system, that's both functional and fast (ok, it could be even faster by optimizing it a little further). And when I say functional I say it has everything I need at the moment.

There is only one downside to Chyrp: the number of themes available is quite small, but the upside to this is that the default theme that comes with it (and which you can see over here) is really nice (or at least I like it).


I'll be sure to dive in and tune it a little bit more, just to see how fast I can get it to be. Oh, and my error log is empty (and I'm having my error reporting set to E_ALL).

10:27 PM | 0 Comments | Tags: , ,
← Previous Next → Page 2 of 3