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.
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.
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.
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.
Link to Play: http://iris.kiristar.com/mv3/
Link to Source: https://bitbucket.org/epb9000/marvie/
I wrote a simple class to get repeatable random numbers out of an input seed. I’ll post it here in case someone else would find such a thing useful. It is based on SHA1 rounds. After a number of any kind is fetched, another round of SHA1 is applied.
Download it here: RepeatablePseudoRNG
The class has 3 different methods for retrieving random numbers.
I’m building a responsive WordPress site, based on the work already done by the team on Twenty Thirteen, for work. I ran into a bit of an issue though when my masthead image worked fine on desktop browsers, but was broken in mobile browsers. It was like the image was too large or too small for the div I was positioning it in on some devices.
Well, turns out it was caused by a difference in size between physical pixels and CSS pixels on the device. My header and divs all had positions and sizes defined in CSS pixels and were sitting atop this background image. However the image was being sized based on physical pixels. With the mismatch that occurred, the elements no longer lined up properly. The solution was simple enough however: just add a
background-size declaration that set the background image’s size in CSS pixels explicitly.
A question was posed on StackOverflow regarding html anchor links like ‘#test’, and how you might go about preserving them. However, it got deleted before I could post my answer. This is current as of today, May 22, 2013.
If you are using a version of TCPDF less than 5.9.193, links that start with `#` need to be changed to reference a page number and, optionally, Y position. For example, `
#3,4.5` to jump to page 3 at position 4.5.
As of 5.9.193, you can link to named destinations with html links this way. However, for this to work, you need to add the named destination yourself with the `
setDestination` method.  So with the example of `
#test` you’ll need to have created a named destination called `
test` with `
For an example of how this might be used, see the feature request that got it added: Feature request #265 HTML href link to destination or bookmark
[1.] As far as I’ve experienced, these do not seem to work in Firefox’s current PDF.js reader however.
The other day I ran across an interesting question on Stack Overflow regarding the use of indic fonts with TCPDF. Languages like Tamil and Malayalam fall into this category. [How can I create Malayalam PDF using TCPDF in PHP?] At first I thought it was just a simple font issue, but that was not the case. Even with font subsetting off, and trying a number of different Malayalam capable fonts, I was having the same problem the question asker was facing. I began googling for information regarding Malayalam and TCPDF, but to no avail. I found out that Tamil was a related script, so I did searches on that and the outlook was not good regarding proper rendering in TCPDF.
Finally after switching my google queries to specifically search for information about indic script support in TCPDF, I found this comment by a person called “Santhosh” regarding TCPDF’s lack of indic script support:
It is technical limitation. For TCPDF, the true type font need to be converted to afm format first, then for each script, the diacritics or ligature rules are implemented in tcpdf itself. That is what done for adding Arabic/Persian support. For complex scripts this is not a correct approach. Indic shaping engines like Pango has evolved by taking about 10 years. The shaping logic is very complex and duplicating it inside a PDF library is wrong approach. Instead the PDF library should depend on Pango or the upcoming Harfbuzz rendering engines. The PDF export library in Mediawiki uses reportlab pdf library. That also attempts to the rendering by itself. And ended up in having no support for any Indic languages and many bugs for Arabic scripts(Note that this extension is disabled in many Indian wikiprojects). Fonts are not enough for rendering, a shaping engine is also required for complex script to interpret the glyph formation rules. This is what PyPDFLib is trying to solve by using Pango for script rendering and Cairo for graphics.
I’m happy to have come across his posts as I might’ve banged my head against a wall trying to answer this Stack Overflow question for a while. I don’t know anything about these languages so I don’t think I could have answered the question as quickly or as thoroughly as I did if it weren’t for finding this.
You can read the full blog post and comment thread here: Creating a new Language ecosystem- Sourashtra as example