Posts Tagged: php

Image Color Dominator

Most anyone who’s used iTunes’ album view will know about their color picking mechanism.  I was curious about how this might be done and found this question on Stack Overflow: How does the algorithm to color the song list in iTunes 11 work?

So I set about creating an equivalent in PHP.  I settled on using the IMagick PHP extension for grabbing pixel data and doing blurs.

The Results

mizu Mizu (Water)

moon Tsuki (Moon)

fall Aki (Fall)

Chibi Chibi ^_^

The How

It’s largely based on the accepted answer given on the Stack Overflow question mentioned earlier. Except I separate potential highlights from the selected background based on a luminance ratio which produces more readable text, and there’s some additional logic for trying to pick contrasting highlight colors.

The Source

Source is available on BitBucket: https://bitbucket.org/epb9000/image-color-dominator/ Not much in the way of documentation, so hopefully the comments on the class aren’t horrifically confusing. I’ll re-read them later and maybe make changes.

Ludum Dare: Marvie!

I produced an entry for this month’s Ludum Dare. It’s a traversal memory game where you have to find your way back home, but you can only pick one path forward, picking wrong forces you to reset.

A brief description:

Marvie is spacefaring alien and can only travel along asteroids. But Marvie has a problem.

He kind of disintegrates every asteroid he touches. He can’t help it. His psychologist says the condition will only get worse with age. How tragic.

Marvie!

Link to Play: http://iris.kiristar.com/mv3/
Link to Source: https://bitbucket.org/epb9000/marvie/

Implemented almost entirely in JavaScript, this uses the DOM to render the playing area.

Get the Bounding Box of an SVG Path

There may be times you need to find the bounding box of an SVG path. One way to find it would be to parse the path and then apply any group transformation on it to find the range of X and Y coordinates the object occupies. However that’s a bit of code, and I’m quite a bit lazy, so I decided to try another approach: rasterize the path object by itself and find where in the image it was drawn.
Continue reading

Resize and Crop to a specific width x height with a crop suggestion point.

I really don’t have a shorter description for this.  I was working on a personal project the other day and realized that this might be a nifty function.  Basically, you know all those snippets to make cropped thumbnails (squares and the like), and how most of them either center or crop to the top of an image.  I wanted a new function that would crop to most any size I desired and any position on the image I desired without the need to change any code, only parameters.  And thus img_resize_crop was born.

Continue reading

SVG to online coloring-sheet SWF

You can do quite a bit of unorthodox stuff with PHP.  If you head over to epbsoft.com, you’ll find several flash coloring sheets I made with PHP, not Flash.  (Sort of anyway.)  I make them by first creating specially formatted SVG (Scalable Vector Graphics) files and feeding them to a PHP script that writes ActionScript files that are then compiled by MotionTwin ActionScript compiler.  As far as capabilities, it’s not all that capable.  I have to jump through a couple of hoops to make an SVG that my ActionScript generator can actually parse properly, but when it works, I like the results.

svg-to-coloring.php.zip <– The source code is available if you want to take a look at how it works.