KrisWillis.com

Flower

Posts Tagged ‘PHP’

Shorten URLs and post to Twitter with PHP and cURL

I recently had the task of automatically “tweeting” when a new article was posted to one of the websites I had built, it turns out to be a pretty simple operation thanks to both Twitter and Bit.ly providing a straight forward API. An account with Bit.ly does have to be opened to obtain an API key.

I decided to use the built-in cURL functionality of PHP for interacting with the APIs. This code uses some of the JSON functions introduced in PHP 5.2.0 so a recent install of PHP is required as the Bit.ly API responds with a JSON string. On to the code…
(more…)

Recolouring images with PHP

Blue roseAbout a year ago I was working on a project where one of its features allowed the user to upload an image, select a colour on the image with a colour picker tool, then select from a group of colours to replace the picked colour with. I had a somewhat stable build running where it simply replaced the hue of the picked colour – Introducing saturation and value changes invoked a number of ‘random’ glitches and odd colour effects. This feature was subsequently dropped from the project due to it costing too much to continue developing.

Skip forward about a year and I find this script knocking around on a back-up disc, so I decide to put some more development time in purely for my own satisfaction of enhancing it. I have made it work to a nearly passable level, it works nice on images with isolated high contrasting colours. I created a function to create a tiled pop-arty graphic from an inputted image too just for fun. For example, input this and it will spit out this. There is plenty of room for improvement: You can’t convert colours to or from white/black and it replaces all instances of a colour, not a flood-fill effect. So, on to the code… (more…)