Windows Server + IIS + PHP 5.3 + ImageMagick + PDFs

After 3 days and hours of frustration, here is the steps to follow for getting php_imagick working on Windows server running IIS:

  • make sure everything you install is 32-bit – this is because PHP is 32-bit, and introducing any 64-bit component will break the whole thing
  • download php_imagick here: http://windows.php.net/downloads/pecl/releases/imagick/3.1.2/php_imagick-3.1.2-5.3-nts-vc9-x86.zip
  • place only the php_imagick.dll file in the “ext” subdirectory of PHP
  • install a legacy version of ImageMagick – this is because as the forum thread http://stackoverflow.com/questions/8457744/installing-imagemagick-onto-xampp-windows-7 points out, PHP 5.3 is compiled with a different version of MSVC than the latest version of ImageMagick, and the two don’t talk to each other. Unfortunately, ImageMagick doesn’t keep archives of old versions, but thankfully other sites do: http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/binaries/ImageMagick-6.6.5-10-Q16-windows-dll.exe
    For simplicity sake, install the file in “C:\ImageMagick”
  • install a legacy version of GhostScript – again, this is to make sure the versions are compatible with each other. Again, Ghostscript themselves don’t seem to keep legacy files, but you can get them SourcrForge: http://sourceforge.net/projects/ghostscript/files/GPL%20Ghostscript/8.62/gs862w32.exe/download
    For simplicity sake, install the file in “C:\Ghostscript”
  • After all this, ImageMagick still won’t see Ghostscript as a delegate for handling PDF’s – you must edit the “config\delegates.xml” file and replace all instances of “@PSDelegate@” with the full path to the Ghostscript binary (note the forward slashes) as described http://stackoverflow.com/questions/13304832/ghostscripts-file-path-in-imagemagick: C:/Ghostscript/8.62/bin/gswin32c.exe
  • At this stage, any command-line testing of the ImageMagick to Ghostscript communication will probably work – but it won’t work under IIS. This is because by default, Ghostscript uses “C:\Windows\Temp”, but IIS doesn’t have permission to that directory. You must grant read/write access to that directory to “IIS_IUSRS” (or php_imagick will keep reporting that there is no delegate) as explained here: http://www.wizards-toolkit.org/discourse-server/viewtopic.php?f=1&t=24757&p=110439&sid=35e443f4faf1b92d68632a72c4000d3e#p110439
  • Finally – REBOOT! None of this will work without rebooting at least once so the entire OS has references to the newly installed software and libraries.

With any luck, you should now have a working php_imagick installed – you can confirm (at least part) of this using phpinfo() – although this may report php_imagick installed, it’s not a guarantee that PDF support will be working. You won’t know that part until you actually try to read in a PDF.

REAL Subdomains under Linode

While trying to add a sub-domain to my Linode account, I did the typical Google search to see if someone else had done so already, and I could just copy their instructions. Alas, there were plenty of posts titled “Subdomain on Linode” (or something to that effect), but they all only showed how to register a host under the DNS, and set up the <VirtualHost> records under Apache.

A host is not the same as a sub-domain.

Let’s assume we have a domain “mydomain.com”. Adding in “lab.mydomain.com” as an “A” record will simply make a host. You cannot then do “work.lab.mydomain.com” using this method – something which should be perfectly acceptable under an actual sub-domain.

Herewith, I present the correct procedure for adding in a sub-domain under the Linode DNS (using the above example of “mydomain.com”).

  1. Under the Domain zone for “mydomain.com”, add in the following “NS” records:
    1. ns1.linode.com -> lab.mydomain.com
    2. ns2.linode.com -> lab.mydomain.com
    3. ns3.linode.com -> lab.mydomain.com
    4. ns4.linode.com -> lab.mydomain.com
    5. ns5.linode.com -> lab.mydomain.com
  2. Create a new domain zone for “lab.mydomain.com”

Presto. You can now add in host records such as “www.lab.mydomain.com” or whatever you want.

My Problem With TV Streaming Websites

I don’t have TV – either cable or satellite. So when I want such entertainment, I just turn to on-line streaming (Netflix, Crackle, etc.) yet I have a problem with all of the ones I’ve found – they are so “website”-centric, that if you are actually a bit of a power user, it becomes an encumbrance to have a browser tab/window open to keep it streaming. To me, it’s a lot easier to run a desktop app which can be dynamically sized, nice reduced interface – think VLC here.

Anyway, that’s my pet peeve with it.

Does anyone actually use QRCodes?

The title says it all – I’ve now worked for 2 separate companies who have had to implement QRCode printing in order to cater to the whims of clients, and yet when it comes times for analyse sources using Google Analytics, we find that virtually nobody actually uses these things.

For example, one of our clients generates 10,000 unique visitors per month – after 2 months of QRCodes, we noticed a whopping 2 hits coming from the QRCodes. Now, to me, the costs involved with having to create these things, and then find printers who will support it, and produce something actually usable just doesn’t make financial sense for 2 whole hits.

I know it’s supposed to be something to catch onto the whole mobile wave right now, but really, it seems to be something people just aren’t interested in – does anyone else have a differing story?

WordPress Shortcodes – My Way

As anyone whose work in WordPress whose tried to create their own shortcodes knows, it can be a nuisance. Trying to come up with unique names for the shortcodes so as not to cause conflicts, supporting nested shortcodes, etc., etc. It can be a challenge.

Instead of using functions, however, I’ve started using enclosures and classes. Such a class itself registers shortcodes which it can have embedded. And to overcome the actual shortcode tag itself conflicting – I’ve found you can “namespace” those, too. Here’s an actual example:

<?php

namespace sunsport\shortcodes;

/**
 * This class provides the functionality for creating the HTML structures for
 * the frontpage tiles
 *
 * @author ncrause
 */
class Tiles {
    public function __construct() {
        add_shortcode('sunsport:tiles:create', array(&$this, 'create'));
        wp_enqueue_style('sunsport-tiles', '/css/tiles.css');
    }
    
    public function __destruct() {
        remove_shortcode('sunsport:tiles:create');
    }
    
    public function start($atts = array(), $content = null) {
        include __DIR__ . '/fragments/tiles/start.php';
    }
     
   public function create($atts = array(), $content = null) {
        extract(shortcode_atts(array(
            'href' => '/',
            'img' => '/img/image_missing.png'
        ), $atts));
        
        include __DIR__ . '/fragments/tiles/create.php';
    }
}

add_shortcode('sunsport:tiles:start', function($atts, $content) {
    $instance = new Tiles();
    
    return $instance->start($atts, $content);
});

So, what we have here is a shortcode “sunsport:tiles:start” which creates an instance of our class. That instantiation registers a new shortcode “sunsport:tiles:create”, which would be unavailable otherwise, thus we avoid have to check to make sure it’s properly enclosed in a parent “start” shortcode, and we gracefully deregister it at the end of the run.

It’s probably worth include the “fragments/tiles/start.php” file just for reference:

<div class="sunsport-tiles">
    <?= do_shortcode($content) ?>
    <div class="clear"></div>
</div>

And here’s the actual usage:

[sunsport:tiles:start]
  [sunsport:tiles:create img="img/tiles/photo_button01.png" href="/products"]Vinyl Lettering[/sunsport:tiles:create]
  [sunsport:tiles:create img="img/tiles/billboard_photo.png"]Billboard[/sunsport:tiles:create]
  [sunsport:tiles:create img="img/tiles/photo_button03.png"]The Company[/sunsport:tiles:create]
[/sunsport:tiles:start]

There’s is one word of warning – do not do a naming convension like this:

  • parent shortcode – sunsport:tiles
    • child shortcode – sunsport:tiles:create

The child shortcode will never fire. For some reason, it seems WordPress doesn’t actually read in the full shortcode in this scenario – instead of “sunsport:tiles:create” firing, WordPress will simple re-run “sunsport:tiles”.

That caveat aside, I find this feels a lot cleaner and less collision-prone than other examples I’ve seen.

Another “WTF?!” IE9 Bug

With Internet Explorer’s complete lack of support for any of the neat and useful CSS styles, one always has to revert to Microsoft’s disgusting “filter” hack. The filters don’t take in very many useful parameters (such as color stops in gradients) and disable text anti-aliasing. 

But here’s something you probably really didn’t see coming – under IE9 only (this doesn’t affect IE8), filters completely cripple events. If you define any mouse over or even click events, they will not fire.

This created a situation where I could no longer use a horizontal sliding accordion, because IE doesn’t support text rotation and uses a … you guessed it … filter.

I hate Microsoft so much … so very very much …

XMLSerializer for Internet Explorer

While trying to convert a jQuery element object into a string, I noticed that all the major browsers support “XMLSerializer”, which does precisely that task. Of course, Internet Explorer is the exception. However, IE does offer the “outerHTML” property on DOM elements, which seems to do the same thing.

I herewith present an extremely short JavaScript snippet which allows global use of XMLSerializer

if (!window["XMLSerializer"]) {
    
    window.XMLSerializer = function() {
        
        this.serializeToString = function(element) {
            return element.outerHTML;
        }
        
    }
    
}

Why I Think Governments Still Hide UFOs

So, I’m watching some UFO documentaries on YouTube yesterday and today, and the one question which keeps coming up is why would governments (especially the US) keep UFOs a secret.

Here’s my take on it – it would cost too much to admit it now. Financially.

Follow me on this one – you have a “cold war ” between two super powers, each of which is trying to one-up the other. Okay, so it makes sense to keep anything a secret in the hopes of gaining an advantage over the other. However, in order to make sure you keep the secret, you have to deal with leaks. The best way of doing this is to destroy the reputation and careers (and ultimately lives) of individuals who may come forward with what they know. This not only discredits the reports of UFOs, but also strikes fear into anyone thinking of reporting an incident, for fear of having their lives destroyed, too.

In the run of time, the cold war ends – but now you have a problem. Even though you don’t have an enemy of that magnitude anymore, you’ve now unjustly destroyed the lives of hundred (thousands?) of people in your own country. Can anyone spell “class-action lawsuit?”

Imagine the field day lawyers would have in a situation where the government now completely admits that UFOs are real, they’ve always been real, and they (the government) has always known about it. This would mean the government intentionally lied outright, causing the wilful destruction of people’s lives. Yeah, the government would get sued into the group.

At this point, they simply cannot admit it, not because of any secret society pulling the strings, but simply because it would bankrupt them.

Just a thought.

Is It Time For More SVG?

I’ve always been a proponent of SVG, even back when everyone was gung-ho with using Flash for every little thing, whether it was a good idea even back then or not.

However, recently I’ve started thinking that perhaps it’s time to start taking it a lot more seriously. With the obvious demise of Flash as a main-stream RIA choice; greater support in all the major browsers; and with Apple pushing Retina displays on their laptops as well as tablets, I think it’s time to start moving away from pixel-defined websites and raster graphics to using “em”-defined websites and SVG graphics.

The combination makes perfect sense – it’s clear you cannot rely on website layouts which are strictly defined using “px” unit-of-measure – that would result in a website being 1000px wide (a good idea if you want to support 1024 x 768 screen resolutions) looking ridiculous on ultra-high resolution displays (such as retina). The obvious problem then becomes fitting graphics in PNG and other raster formats into this different unit-of-measure. Sure, you could scale the graphics image, or have several versions of it and try to detect the screen resolution, but all of that becomes moot if you use SVG, which by it’s very design will scale up and down without pixelation.

What I find interesting is that Sun saw the writing on the wall (even before they were taken over by Oracle) when it comes to greater resolutions, which is why the “Nimbus” look and feel for Swing was specifically designed using vector graphics and not bitmaps/raster images.

As with everything in web programming, however, you’re always stuck with users refusing to upgrade their version of IE to something even vaguely useful (I’m talking IE9 at least), or moving onto a better browser. I wonder if perhaps as an industry we (as programmers, business people, scientists) need to drag consumers along, kicking and screaming. Imagine, if you will, if 90% of all major websites dropped support for IE8 and below tomorrow morning. Users would have no room to complain, and would simply be forced into upgrading. No more “why can I use IE6 on my bank website, but not on your website?”

Bliss.

IE Sucks – Deal With It

I’m so tired of Microsoft fan-boys trying to claim that IE isn’t as crap as everyone else with a brain keeps saying. Their typical rhetoric is that IE can do everything the other browser can do, just using a “hack”.

Well, this would be the crux of my problem with it – why the hell must everything be a hack? And for the record, the hacks don’t work right.

Here’s an example – background gradients. All the major browsers (including mobile browsers) all support some fort of native background gradients. IE doesn’t have anything like that. BUT WAIT! Microsoft fan-boys will point to the all-powerful “filter” CSS property. Yeah, great, here’s the problem – the minute you run anything through Microsoft’s “filter” rubbish, all the text loses anti-aliasing. And believe me – it’s noticeable. I actually had one of my most unobservant, tech-unsavvy (not a real word, I know) customers complain that the text “looked like shit”.

And he was right.

So, really – until you can write a website which looks perfect under IE without hacks (and without having to always fall back in static images everywhere), fan-boys should just shut the heck up and accept that Internet Explorer is a massive, steamy pile of rat-turds.

And as for customers – given the ease with which other browsers can now be downloaded and installed, there’s absolutely no excuse any more for using it. If your IT guy says there’s no reason to switch, then you need a new IT guy, because you’re currently working with a monkey.