beefsack on 2009-07-01 07:38:23
Google Chrome has to be my favourite browser, having a great compact interface (which works particularly well on my NC10), as well as being lightning fast. The one reason why I haven't completely switched over from Firefox is because of a lack of extensions, and in particular an ad blocking extension. There are a couple of options, and today I found the one that works perfectly for me.
When trying to enable ad blocking for browsers you have two options, internally (usually with extensions, such as the fantastic Adblock Plus for Firefox) or externally, usually via a proxy (such as using Privoxy, which works really well).
I've been using Privoxy with Chrome until a few hours ago and it has been working well enough for me. Basically, you set an application (such as Chrome) to use Privoxy as a proxy for your internet connection, and Privoxy will filter the incoming content before the browser touches it. The great thing about using something externally like Privoxy is that you can centralise your filtering if you use more than one application that needs to be filtered, and can be set up to run as a proxy for a LAN. It is also very versatile, and while it works well blocking ads it is capable of filtering for pretty much anything. The Privoxy site has basic instructions on how to get started.
Today, however, I found the solution that works perfectly for me. I was never really happy using Privoxy as it was constantly running, and while the overhead was very minimal (virtually nothing), some overhead is still much more than no overhead. I use my Windows partition solely for gaming so performance is key for me, and I only require ad blocking for if I have to browse the net in Windows and not while I am gaming. Therefore for me an internal solution would be perfect, only consuming resources when I am running the web browser. Firefox with Adblock Plus is perfect for this, and now Chrome with the AdSweep extension works brilliantly too.
AdSweep has been around for a while using Javascript in a wide variety of browsers, and has been made into a Chrome extension recently. Chrome has supported extensions in recent beta and dev builds (Chromium developers have released a tool to switch from stable release to beta or dev builds). After switching to a new build, Chrome can be launched by adding the --enable-extensions argument to enable extensions. For me, I made a shortcut to "C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe --enable-extensions". After launching with extensions enabled, head to the AdSweep page and download AdSweep.crx. After downloading in Chrome, it should automatically run the extension, and ads should now be blocked internally. To check locally installed Chrome extensions, point chrome to chrome://extensions/. So far I haven't found AdSweep to noticeably affect performance when browsing.
Unfortunately, the AdSweep developer has discontinued the AdSweep project as of about a month ago, but that doesn't stop it from working very well. Hopefully once extensions in Chrome hit the stable release, lots of people will benefit from this great extension, and hopefully development will continue one day. I've found AdSweep to be fantastic and the developer has done a wonderful job releasing it as what I can see is the first native Chrome ad blocking extension.
As a side note, Firefox 3.5 came out today. I've been using Firefox 3.5 pre release versions for a while now in Linux and it is much much faster than older Firefox releases (Mozilla claims twice as fast as Firefox 3 and 10 times faster than Firefox 2). This browser war is doing amazing things for consumers, as instead of being fought over incompatible Javascript features, it is being fought over standards compliance, performance, security and stability. Chrome has it's nose out in terms of performance and UI which are the deciding factors for me, but is behind Firefox in terms of features, and the Firefox extension library is immense. Firefox and Chrome are also implementing a lot of the proposed feature set of HTML 5, which is really going to change the web, particularly with the canvas element (which has already spawned in browser 3D engines) and the video element. Both of these elements look to replace the heavy dependence on flash for dynamic page content such as for games and embedded video in web pages.
When trying to enable ad blocking for browsers you have two options, internally (usually with extensions, such as the fantastic Adblock Plus for Firefox) or externally, usually via a proxy (such as using Privoxy, which works really well).
I've been using Privoxy with Chrome until a few hours ago and it has been working well enough for me. Basically, you set an application (such as Chrome) to use Privoxy as a proxy for your internet connection, and Privoxy will filter the incoming content before the browser touches it. The great thing about using something externally like Privoxy is that you can centralise your filtering if you use more than one application that needs to be filtered, and can be set up to run as a proxy for a LAN. It is also very versatile, and while it works well blocking ads it is capable of filtering for pretty much anything. The Privoxy site has basic instructions on how to get started.
Today, however, I found the solution that works perfectly for me. I was never really happy using Privoxy as it was constantly running, and while the overhead was very minimal (virtually nothing), some overhead is still much more than no overhead. I use my Windows partition solely for gaming so performance is key for me, and I only require ad blocking for if I have to browse the net in Windows and not while I am gaming. Therefore for me an internal solution would be perfect, only consuming resources when I am running the web browser. Firefox with Adblock Plus is perfect for this, and now Chrome with the AdSweep extension works brilliantly too.
AdSweep has been around for a while using Javascript in a wide variety of browsers, and has been made into a Chrome extension recently. Chrome has supported extensions in recent beta and dev builds (Chromium developers have released a tool to switch from stable release to beta or dev builds). After switching to a new build, Chrome can be launched by adding the --enable-extensions argument to enable extensions. For me, I made a shortcut to "C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe --enable-extensions". After launching with extensions enabled, head to the AdSweep page and download AdSweep.crx. After downloading in Chrome, it should automatically run the extension, and ads should now be blocked internally. To check locally installed Chrome extensions, point chrome to chrome://extensions/. So far I haven't found AdSweep to noticeably affect performance when browsing.
Unfortunately, the AdSweep developer has discontinued the AdSweep project as of about a month ago, but that doesn't stop it from working very well. Hopefully once extensions in Chrome hit the stable release, lots of people will benefit from this great extension, and hopefully development will continue one day. I've found AdSweep to be fantastic and the developer has done a wonderful job releasing it as what I can see is the first native Chrome ad blocking extension.
As a side note, Firefox 3.5 came out today. I've been using Firefox 3.5 pre release versions for a while now in Linux and it is much much faster than older Firefox releases (Mozilla claims twice as fast as Firefox 3 and 10 times faster than Firefox 2). This browser war is doing amazing things for consumers, as instead of being fought over incompatible Javascript features, it is being fought over standards compliance, performance, security and stability. Chrome has it's nose out in terms of performance and UI which are the deciding factors for me, but is behind Firefox in terms of features, and the Firefox extension library is immense. Firefox and Chrome are also implementing a lot of the proposed feature set of HTML 5, which is really going to change the web, particularly with the canvas element (which has already spawned in browser 3D engines) and the video element. Both of these elements look to replace the heavy dependence on flash for dynamic page content such as for games and embedded video in web pages.
Today I'm adding a recent little project called mamehof written in Python together with a friend of mine, Steve Taylor.
mamehof scrapes the Hall of Fame data from MAWS and outputs an ini to be used as a custom folder for MameUI.
The script is available to download from the project page, along with the ini output from a scrape today.
mamehof scrapes the Hall of Fame data from MAWS and outputs an ini to be used as a custom folder for MameUI.
The script is available to download from the project page, along with the ini output from a scrape today.
beefsack on 2009-06-01 01:13:11
The Chromium guys have started to release Linux builds which is fantastic. Chrome on Windows is blisteringly fast, and coming from a slow Firefox in Linux under both Fedora and Ubuntu, it is very nice to have a browser that is very quick. It takes a little bit of work to get it going through, and I will detail the process below.
This process is adapted from hicham.haouari's comments on Chromium issue 12562, which is what I used to get the browser working in the first place. The process detailed here will include very slightly altered instructions to get it to work on x86_64 systems, and will work if launched from another folder than the extracted folder. This was important for me because I wanted Chromium to be in my Main Menu.
So on to how to do it:
First you will need to download the latest build of Chromium, which obviously will be the highest numbered version. Extract the archive somewhere.
Trying to launch Chromium on Fedora at the moment gets the following error:
Fedora actually has NSS installed, but it has different names for the files. The solution is to create symbolic links to the library files with the names that Chrome is looking for. So, from inside the extracted Chrome folder (32-bit only):
There is another option to do this, which is also the only option for 64-bit as 64-bit doesn't have the 32-bit libraries that Chrome requires. This is to get the relevant required 32-bit libraries for Chrome and place them in the library path. Download the libraries and extract them to the lib folder inside the Chrome folder. I have already renamed the libraries to suit what Chrome looks for.
After this, you will need to create a bash script in the Chrome folder to add this new lib folder to the PATH and then launch the Chrome binary. Create a file in the Chrome folder called launch-chrome.sh and use a text editor to paste the following text in it:
And finally, add execution permissions to the new script either using properties in Nautilus or doing the following from terminal:
Now, you can run Chrome in Fedora by running the script using ./launch-chrome.sh and you are also able to run it from Nautilus and add it to the Main Menu.
If there are still errors (as some people have experienced on the issue page linked earlier), it is possible that more libraries are required. If you get an error saying you are missing libgconf-2.so.4 or libasound.so.2, run:
This process is adapted from hicham.haouari's comments on Chromium issue 12562, which is what I used to get the browser working in the first place. The process detailed here will include very slightly altered instructions to get it to work on x86_64 systems, and will work if launched from another folder than the extracted folder. This was important for me because I wanted Chromium to be in my Main Menu.
So on to how to do it:
First you will need to download the latest build of Chromium, which obviously will be the highest numbered version. Extract the archive somewhere.
Trying to launch Chromium on Fedora at the moment gets the following error:
[beefsack@beefsack lib]$ /home/beefsack/Download/chrome-linux/launch-chrome.sh /home/beefsack/Download/chrome-linux/chrome: error while loading shared libraries: libnss3.so.1d: cannot open shared object file: No such file or directory
Fedora actually has NSS installed, but it has different names for the files. The solution is to create symbolic links to the library files with the names that Chrome is looking for. So, from inside the extracted Chrome folder (32-bit only):
[beefsack@beefsack chrome-linux]$ mkdir lib [beefsack@beefsack chrome-linux]$ cd lib [beefsack@beefsack lib]$ ln -s /lib/libnspr4.so libnspr4.so.0d [beefsack@beefsack lib]$ ln -s /lib/libnss3.so libnss3.so.1d [beefsack@beefsack lib]$ ln -s /lib/libnssutil3.so libnssutil3.so.1d [beefsack@beefsack lib]$ ln -s /lib/libplc4.so libplc4.so.0d [beefsack@beefsack lib]$ ln -s /lib/libplds4.so libplds4.so.0d [beefsack@beefsack lib]$ ln -s /lib/libsmime3.so libsmime3.so.1d [beefsack@beefsack lib]$ ln -s /lib/libssl3.so libssl3.so.1d [beefsack@beefsack lib]$
There is another option to do this, which is also the only option for 64-bit as 64-bit doesn't have the 32-bit libraries that Chrome requires. This is to get the relevant required 32-bit libraries for Chrome and place them in the library path. Download the libraries and extract them to the lib folder inside the Chrome folder. I have already renamed the libraries to suit what Chrome looks for.
After this, you will need to create a bash script in the Chrome folder to add this new lib folder to the PATH and then launch the Chrome binary. Create a file in the Chrome folder called launch-chrome.sh and use a text editor to paste the following text in it:
#!/bin/bash export LD_LIBRARY_PATH=`dirname $0`/lib:$LD_LIBRARY_PATH `dirname $0`/chrome
And finally, add execution permissions to the new script either using properties in Nautilus or doing the following from terminal:
[beefsack@beefsack chrome-linux]$ chmod +x launch-chrome.sh [beefsack@beefsack chrome-linux]$
Now, you can run Chrome in Fedora by running the script using ./launch-chrome.sh and you are also able to run it from Nautilus and add it to the Main Menu.
If there are still errors (as some people have experienced on the issue page linked earlier), it is possible that more libraries are required. If you get an error saying you are missing libgconf-2.so.4 or libasound.so.2, run:
[root@beefsack ~]# yum -y install libgconf-2.so.4 alsa-lib.i586
In the last couple of days, Moblin, a netbook focussed Linux distribution with particular focus on an easy simple interface and integration of social networking. I downloaded a copy today and gave it a spin on my Samsung NC10.
You are able to copy the live image to a USB drive using the following command:
My USB drive showed up as /dev/sdd, make sure you use the right one so you don't lose any data on another drive. Use "fdisk -l" to see a list of media.
After getting the live USB working, I plugged it in and the first thing I noticed was the speed that it booted. Moblin is very light weight and it really shows during boot and also during general use. Saying light weight however doesn't say that the interface suffers because of it, it is actually an amazingly clean interface that is very easy on the eyes. Navigation is done via a drop down bar at the top of the screen, which consists of a clock with date on the left, eight major tabs in the middle (described later), and notification style icons on the right (power, volume and networking).
The eight major tabs in the navigation bar (from left to right) are:
m_zone:
The m_zone is the start page for Moblin, which summarises a lot of general information. It is split into three columns, each showing a different type of information. The left column summarises calendar entries and has a todo list, all managed by Dates which is neatly integrated into Moblin. The middle column shows frequently visited web pages, and clicking on them opens the pages in the browser. The right column has social networking information and other "Web Services".
status:
The status tab shows the social networking focus in Moblin. In the beta, all you can do is change your Twitter status, however it is fairly obvious that more social networking sites like possibly Facebook and MySpace will also be integrated.
people:
The people tab works like an IM, where you can add accounts and chat with people. In account configuration, you are able to configure Jabber, Google Talk (which uses the XMPP protocol like Jabber) and Salut accounts. I tried to add a Google Talk account but was unable to get it to connect for some reason, so I'm unable to comment on how well the people tab works in action.
internet:
Fairly straightforward, when clicking the internet tab all that appears is an address bar. Upon entering an address, the navigation bar disappears and a full screen web browser (Mozilla based) launches. The web browser, like Moblin in general, is very simple and clean. There is a navigation bar with back, forward, address, settings and exit, below which is a tab bar. Apart from that, a very large amount of area is free for the web pages themselves, which is great for the smaller screen real estate on netbooks and MIDs. The browser displays content well, and passes acid tests 1 and 2, and scoring a respectable 94 on acid test 3. Of note, there is no settings page yet and right clicking doesn't open any menu. Like in most tabbed browsers, a middle click will open a link in a new tab.
media:
Also quite straightforward, the media tab is where users access pictures, music and video. The media tab has a search bar at the top for searching through media, and an as yet unimplemented playlist on the right. The video player is based on gstreamer, so a vast array of codecs will be supported.
pasteboard:
The pasteboard tab is a system wide clipboard management app, where the user can store copied text for use later. It's useful, but you've gotta question if it is important enough to be made a main shortcut.
applications:
The application tab works like a main menu, with access to the range of apps installed. All of the applications are organised into expandable groups, including a settings group. There are standard basic apps like a calculator, terminal, text editor and file browser, and also has a few games installed (including Neverputt which is an awesome little 3D minigolf game). When opening an app, if an app is already open the user is prompted to open in the current "zone" or to open in a new one. Zones are pretty much just workspaces, and can be accessed via the zones tab or by using ctrl+alt+arrow. There is also a search bar at the top of the application tab which is quite useful.
zones:
The zones tab is a simple one which works like a workspace selector. At the moment, only selection of zones is possible and it isn't possible to open any new ones (users are prompted to open a new one when opening an application).
The interface is also very intuitive, and even though it is quite unique it is still quite easy to navigate. Having also used Ubuntu Netbook Remix, it is clear each have their own strengths. I believe that in Moblin, navigation through apps in the same zone and navigation through zones is a little bit cumbersone. UNR on the other hand uses maximus which integrates a programs title bar into a window list at the top of the screen, which uses a bit more room than Moblin, but it makes window navigation easy as non active windows get an icon on the bar. However, in a purely aesthetic sense, UNR still has a way to go (particularly the home page), but Moblin looks amazing in nearly every sense while still mainly hitting the mark in terms of usability. It is going to be interesting to see where Moblin goes from here.
You are able to copy the live image to a USB drive using the following command:
dd if=moblin-netbook-ux-beta-20090518-004.img of=/dev/sdd
My USB drive showed up as /dev/sdd, make sure you use the right one so you don't lose any data on another drive. Use "fdisk -l" to see a list of media.
After getting the live USB working, I plugged it in and the first thing I noticed was the speed that it booted. Moblin is very light weight and it really shows during boot and also during general use. Saying light weight however doesn't say that the interface suffers because of it, it is actually an amazingly clean interface that is very easy on the eyes. Navigation is done via a drop down bar at the top of the screen, which consists of a clock with date on the left, eight major tabs in the middle (described later), and notification style icons on the right (power, volume and networking).
The eight major tabs in the navigation bar (from left to right) are:
m_zone:
The m_zone is the start page for Moblin, which summarises a lot of general information. It is split into three columns, each showing a different type of information. The left column summarises calendar entries and has a todo list, all managed by Dates which is neatly integrated into Moblin. The middle column shows frequently visited web pages, and clicking on them opens the pages in the browser. The right column has social networking information and other "Web Services".
status:
The status tab shows the social networking focus in Moblin. In the beta, all you can do is change your Twitter status, however it is fairly obvious that more social networking sites like possibly Facebook and MySpace will also be integrated.
people:
The people tab works like an IM, where you can add accounts and chat with people. In account configuration, you are able to configure Jabber, Google Talk (which uses the XMPP protocol like Jabber) and Salut accounts. I tried to add a Google Talk account but was unable to get it to connect for some reason, so I'm unable to comment on how well the people tab works in action.
internet:
Fairly straightforward, when clicking the internet tab all that appears is an address bar. Upon entering an address, the navigation bar disappears and a full screen web browser (Mozilla based) launches. The web browser, like Moblin in general, is very simple and clean. There is a navigation bar with back, forward, address, settings and exit, below which is a tab bar. Apart from that, a very large amount of area is free for the web pages themselves, which is great for the smaller screen real estate on netbooks and MIDs. The browser displays content well, and passes acid tests 1 and 2, and scoring a respectable 94 on acid test 3. Of note, there is no settings page yet and right clicking doesn't open any menu. Like in most tabbed browsers, a middle click will open a link in a new tab.
media:
Also quite straightforward, the media tab is where users access pictures, music and video. The media tab has a search bar at the top for searching through media, and an as yet unimplemented playlist on the right. The video player is based on gstreamer, so a vast array of codecs will be supported.
pasteboard:
The pasteboard tab is a system wide clipboard management app, where the user can store copied text for use later. It's useful, but you've gotta question if it is important enough to be made a main shortcut.
applications:
The application tab works like a main menu, with access to the range of apps installed. All of the applications are organised into expandable groups, including a settings group. There are standard basic apps like a calculator, terminal, text editor and file browser, and also has a few games installed (including Neverputt which is an awesome little 3D minigolf game). When opening an app, if an app is already open the user is prompted to open in the current "zone" or to open in a new one. Zones are pretty much just workspaces, and can be accessed via the zones tab or by using ctrl+alt+arrow. There is also a search bar at the top of the application tab which is quite useful.
zones:
The zones tab is a simple one which works like a workspace selector. At the moment, only selection of zones is possible and it isn't possible to open any new ones (users are prompted to open a new one when opening an application).
The interface is also very intuitive, and even though it is quite unique it is still quite easy to navigate. Having also used Ubuntu Netbook Remix, it is clear each have their own strengths. I believe that in Moblin, navigation through apps in the same zone and navigation through zones is a little bit cumbersone. UNR on the other hand uses maximus which integrates a programs title bar into a window list at the top of the screen, which uses a bit more room than Moblin, but it makes window navigation easy as non active windows get an icon on the bar. However, in a purely aesthetic sense, UNR still has a way to go (particularly the home page), but Moblin looks amazing in nearly every sense while still mainly hitting the mark in terms of usability. It is going to be interesting to see where Moblin goes from here.
This week I installed the latest preview release of Fedora, having used the latest release of Ubuntu for a few months now.
The latest version of Ubuntu brings with it GNOME 2.26, which includes updates to the main burning application Brasero.
One of the cooler updates was the new notification system (example), which pops up notification bubbles from applications. This works particularly well with Pidgin where user messages pop up in the little unobtrusive bubbles so you can easily see what people are sending you without having the chat window open. I would love to see Banshee integrate in a similar way for new tracks, and it would be great if the notification system can make it's way to other distros because I think it works fantastically well.
Of course, being a new release, it brings with it updates versions of apps in the repos. In particular, OpenOffice 3, and a big one for me, XMoto 0.5 which is a fantastic little motocross puzzle game.
As for Fedora, there have been a lot of big changes too, although most are under the hood. The most immediate change that I see is a much faster boot, and a very snappy interface once logged in. This is particularly noticeable coming from Ubuntu, as I find the Ubuntu a bit slow to boot (especially with a web server installed) and the interface a little bit sluggish at times. Like Ubuntu, Fedora 11 includes GNOME 2.26.
Unlike Ubuntu, Fedora doesn't seem to have any big interface changes. The two that made an impression on me was the removal of sub menus in the System menu (which is great) and also a really nice background that extends when using dual monitors to show a cool Lion head on the right monitor. While Ubuntu comes with a very recent NVidia driver (for my GTX 260), I had to install a new driver manually in Fedora to get the fancy desktop effects.
The big plus for me in Fedora though is all of the developer tools it ships with, including a pre-configured Windows cross-compiler which is a fantastic idea because they are a pain to set up on your own. Another thing that makes Fedora stand out for me is Fedora Eclipse with nearly every plug-in I need (except for PDT which I much prefer to PHPEclipse.
As a general computer user, Ubuntu is brilliant, but as a developer, loading up Fedora is equally great. I'm going to use Leonidas until a stable-ish build of Ubuntu Karmic Koala comes out, and with the releases of Fedora and Ubuntu being staggered I can see myself switching between them every three months or so. It's great to be spoiled for choice :)
The latest version of Ubuntu brings with it GNOME 2.26, which includes updates to the main burning application Brasero.
One of the cooler updates was the new notification system (example), which pops up notification bubbles from applications. This works particularly well with Pidgin where user messages pop up in the little unobtrusive bubbles so you can easily see what people are sending you without having the chat window open. I would love to see Banshee integrate in a similar way for new tracks, and it would be great if the notification system can make it's way to other distros because I think it works fantastically well.
Of course, being a new release, it brings with it updates versions of apps in the repos. In particular, OpenOffice 3, and a big one for me, XMoto 0.5 which is a fantastic little motocross puzzle game.
As for Fedora, there have been a lot of big changes too, although most are under the hood. The most immediate change that I see is a much faster boot, and a very snappy interface once logged in. This is particularly noticeable coming from Ubuntu, as I find the Ubuntu a bit slow to boot (especially with a web server installed) and the interface a little bit sluggish at times. Like Ubuntu, Fedora 11 includes GNOME 2.26.
Unlike Ubuntu, Fedora doesn't seem to have any big interface changes. The two that made an impression on me was the removal of sub menus in the System menu (which is great) and also a really nice background that extends when using dual monitors to show a cool Lion head on the right monitor. While Ubuntu comes with a very recent NVidia driver (for my GTX 260), I had to install a new driver manually in Fedora to get the fancy desktop effects.
The big plus for me in Fedora though is all of the developer tools it ships with, including a pre-configured Windows cross-compiler which is a fantastic idea because they are a pain to set up on your own. Another thing that makes Fedora stand out for me is Fedora Eclipse with nearly every plug-in I need (except for PDT which I much prefer to PHPEclipse.
As a general computer user, Ubuntu is brilliant, but as a developer, loading up Fedora is equally great. I'm going to use Leonidas until a stable-ish build of Ubuntu Karmic Koala comes out, and with the releases of Fedora and Ubuntu being staggered I can see myself switching between them every three months or so. It's great to be spoiled for choice :)
Tags: beefsack.com
beefsack on 2009-05-14 09:36:05
This afternoon I updated beefsack.com to come in line with Zend Framework 1.8.1, which was a bit of work but has cleaned up my code a lot, especially my bootstrap and initialisation code. Now it is much easier to do initialisation code in the bootstrap, as it is now a class and you can implement initialisation as methods to clean things up. I still use a front controller plugin though for extra initialisation after routing.
After all of the changes in 1.8, Zend is a lot simpler to get into, particularly thanks to the new Zend Tool which automates the creation of projects and project components like controllers and views. All of the documentation has been updated too, and the new quick start guide is much more concise and straightforward.
After all of the changes in 1.8, Zend is a lot simpler to get into, particularly thanks to the new Zend Tool which automates the creation of projects and project components like controllers and views. All of the documentation has been updated too, and the new quick start guide is much more concise and straightforward.
I'm doing a project at the moment where I will need to write text on an image using imagettftext, however the text needs an outline and there was no immediate way for me to do this.
In my head there were a couple of possibilities. One was to first write the text in a larger font first with smaller character spacing, however I couldn't find a way to change character spacing without writing each character individually, which would have been a lot of work for me. The second way I thought was to first render the text, then search for and manually colour all pixels within a certain distance of the text, which seemed quite expensive for something that would be run quite frequently.
My final solution was to just render text in the outline colour multiple times in different directions from the text location, and finally render the final text in the middle of that. At first I tried just four outline renders in each of the diagonal directions, however this caused gaps in the outline. The current version also renders orthogonally (making it 8 renders for the outline, and one for the final text) which fills gaps well as long as the outline distance is not too large. Here is an example of my code, which anyone is free to use:
And here is what it looks like:

In my head there were a couple of possibilities. One was to first write the text in a larger font first with smaller character spacing, however I couldn't find a way to change character spacing without writing each character individually, which would have been a lot of work for me. The second way I thought was to first render the text, then search for and manually colour all pixels within a certain distance of the text, which seemed quite expensive for something that would be run quite frequently.
My final solution was to just render text in the outline colour multiple times in different directions from the text location, and finally render the final text in the middle of that. At first I tried just four outline renders in each of the diagonal directions, however this caused gaps in the outline. The current version also renders orthogonally (making it 8 renders for the outline, and one for the final text) which fills gaps well as long as the outline distance is not too large. Here is an example of my code, which anyone is free to use:
<?php
/**
* Writes text using imagettftext with an outline around characters
* @author Michael Alexander http://beefsack.com
*/
function imagettftextoutline(
$image,
$size,
$angle,
$x,
$y,
$color,
$fontfile,
$text,
$outlinewidth = 1, // 1px outline
$outlinecolor = 0 // black
) {
// First offset diagonally
imagettftext($image, $size, $angle, $x - $outlinewidth,
$y - $outlinewidth, $outlinecolor, $fontfile, $text);
imagettftext($image, $size, $angle, $x - $outlinewidth,
$y + $outlinewidth, $outlinecolor, $fontfile, $text);
imagettftext($image, $size, $angle, $x + $outlinewidth,
$y - $outlinewidth, $outlinecolor, $fontfile, $text);
imagettftext($image, $size, $angle, $x + $outlinewidth,
$y + $outlinewidth, $outlinecolor, $fontfile, $text);
// Then offset orthogonally
imagettftext($image, $size, $angle, $x - $outlinewidth, $y,
$outlinecolor, $fontfile, $text);
imagettftext($image, $size, $angle, $x + $outlinewidth, $y,
$outlinecolor, $fontfile, $text);
imagettftext($image, $size, $angle, $x, $y - $outlinewidth,
$outlinecolor, $fontfile, $text);
imagettftext($image, $size, $angle, $x, $y + $outlinewidth,
$outlinecolor, $fontfile, $text);
// Output text
imagettftext($image, $size, $angle, $x, $y, $color, $fontfile,
$text);
}
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $grey);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Output text with outline
imagettftextoutline($im, 20, 0, 10, 22, $white, $font, $text, 2);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);And here is what it looks like:
Tags: beefsack.com
beefsack on 2009-05-07 09:37:21
Today I've been doing a fair bit of work on the beefsack.com backend. One major change was to change every database query to use Zend_Db_Select objects, which has dramatically cleaned up some code and has made some of my more complex SQL statements a lot easier to manage.
I have also disabled Dojo for now due to performance, and have been quite unhappy about how the Dojo Editor outputs. It outputs with some odd characters, and the fact that it converts html safe characters if content is reloaded to the editor is a bit of a security concern for me. It is possible to run scripts and other code when reloading text into the editor, and the only way to stop it is to check and escape input every time it is loaded.
I've decided instead of having a rich text editor that outputs HTML, I'll just use BBCode markup for now and switch to a rich editor again when a better solution comes around.
It's odd, I am much more comfortable typing this up in plain text than in a Javascript editor, I guess that's the nerd in me taking over. Mind you, TinyMCE looks cool, I might give it a spin sometime.
I have also disabled Dojo for now due to performance, and have been quite unhappy about how the Dojo Editor outputs. It outputs with some odd characters, and the fact that it converts html safe characters if content is reloaded to the editor is a bit of a security concern for me. It is possible to run scripts and other code when reloading text into the editor, and the only way to stop it is to check and escape input every time it is loaded.
I've decided instead of having a rich text editor that outputs HTML, I'll just use BBCode markup for now and switch to a rich editor again when a better solution comes around.
It's odd, I am much more comfortable typing this up in plain text than in a Javascript editor, I guess that's the nerd in me taking over. Mind you, TinyMCE looks cool, I might give it a spin sometime.
Tags: beefsack.com
beefsack on 2009-05-07 04:03:45
I spent this morning writing a simple parser for BBCode style tags on beefsack.com. The reason for this is I wanted to add the ability to post monospace properly formatted code in my blog posts, and wanted to do it without writing a Dojo Editor plugin which wouldn't be flexible enough for me.
I found some great proposed components on the way for Zend, being Zend_Markup which seems to be maturing well, and Zend_Syntax_Highlight, which unfortunately hasn't been updated for a while.
Zend_Markup is meant to "provide an extensible way to tokenize and render lightweight markup languages, like BBcode and Textile." Ideally, I would want my Dojo Editor box to output BBCode instead of HTML, and have a parser convert it as needed. This would be particularly handy for me when I write the forums for this site as I want to use BBCode for that as is the standard for most forums around.
I noticed in the code for Zend_Markup they seem to use the PHP function highlight_string if it is passed PHP as a lang attribute. I feel that if a component like Zend_Syntax_Highlight was completed, it could make Zend_Markup very powerful on coding related sites and forums, being able to pass different lang attributes depending on the code that is inside the lang tags. Anyway, I've written a simple parser to detect BBCode style code tags so I'm able to post code on the blog. Here's what it looks like:
I found some great proposed components on the way for Zend, being Zend_Markup which seems to be maturing well, and Zend_Syntax_Highlight, which unfortunately hasn't been updated for a while.
Zend_Markup is meant to "provide an extensible way to tokenize and render lightweight markup languages, like BBcode and Textile." Ideally, I would want my Dojo Editor box to output BBCode instead of HTML, and have a parser convert it as needed. This would be particularly handy for me when I write the forums for this site as I want to use BBCode for that as is the standard for most forums around.
I noticed in the code for Zend_Markup they seem to use the PHP function highlight_string if it is passed PHP as a lang attribute. I feel that if a component like Zend_Syntax_Highlight was completed, it could make Zend_Markup very powerful on coding related sites and forums, being able to pass different lang attributes depending on the code that is inside the lang tags. Anyway, I've written a simple parser to detect BBCode style code tags so I'm able to post code on the blog. Here's what it looks like:
<?php
function thisIsAFunction() {
for ($i = 1; $i < 10; $i++) {
echo "Something $i";
}
}
?>
Which will work in the meantime until Zend_Markup is in an official release.Tags: beefsack.com
beefsack on 2009-05-05 07:09:33
After unloading a truck full of beer at work and digging some holes in the garden, I got around to doing some coding this afternoon.
This afternoon I was playing around with a new Zend component for me, Zend_Feed. Zend_Feed can be used for reading and creating Atom and RSS feeds, and I have used it to aggregate content on beefsack.com.
If your browser supports it, you should see an RSS link on each page which can be used to receive updates to the site. If viewing a specific tag or project, the RSS feed will be tailored to only receive updates from that tag or project.
Zend_Feed has been proof to me once again how flexible Zend is, as I was able to implement it with very few lines of code and virtually no modification to code I had already written. I just created a new controller for RSS, and edited my layout to link to the feed.
Next step, commenting on blog posts, which should be a decent sized update.
This afternoon I was playing around with a new Zend component for me, Zend_Feed. Zend_Feed can be used for reading and creating Atom and RSS feeds, and I have used it to aggregate content on beefsack.com.
If your browser supports it, you should see an RSS link on each page which can be used to receive updates to the site. If viewing a specific tag or project, the RSS feed will be tailored to only receive updates from that tag or project.
Zend_Feed has been proof to me once again how flexible Zend is, as I was able to implement it with very few lines of code and virtually no modification to code I had already written. I just created a new controller for RSS, and edited my layout to link to the feed.
Next step, commenting on blog posts, which should be a decent sized update.