Thursday, November 11, 2010

autolinking images in rich email

So if you have ever done rich email design, you know that it can be a good idea to link every image in the email to a URL in order to increase clicks, but if you have a giant, sliced up design with tons of individual images, it's a pain to assign a link to each one. When I get a case like this, I don't link any of the images (unless they are going to very specific subpages) Instead I let a server script process the page and assign every non-linked image a master link.

Now we don't want to over write existing linked images, so there also has to be a way to leave those alone and just link the "naked" images. Probably could use a little more polish, but here is the basic idea


(PHP)

function autolink($file, $link){
// autolink function
// This function will apply a master link to all images in a page
// provided they are not linked already -- which can be handy for email blasts to get more clicks
// NOTE: if there are any characters, including whitespace
// between the opening A tag and the IMG tag (found in poor HTML), that A tag will
// not be excluded from the main pattern, therefore any enclosed images
// that meet this condition will end up with nested A tags (for the IMG) and the IMG will be linked to the master link.
// however this should not break most browsers if it happens
// for best results, this function should be combined with the noimgborders function
// also available in the hankpants library.

// find all EXISTING linked images and transcode
// them into html entities to hide them from the main REGEX pattern
// (swap these back in later)
$link = trim($link);
$i=0;
$_ = preg_match_all('/\<a\s[^\>]+?\>\<img.+?\>\<\/a>/ism', $file, $alreadylinked);
foreach($alreadylinked[0] as $hello){
$world[$i] = htmlentities($hello);
$file = str_replace ($hello, $world[$i], $file);
$i++;
}
// existing linked images now escaped, run our main link replacement REGEX
$i=0;
$file = preg_replace('/\<img.+?\>/ism', '<a href="'.$link.'">$0</a>', $file);
// swap back in the linked images that were hidden by transcoding
foreach($world as $hello){
$decodelink = html_entity_decode($hello);
$file = str_replace ($hello, $decodelink, $file);
}
return $file;
}

Tuesday, February 16, 2010

Improved version of inline style swap for mail

// version 2 capturing all styles not just dreamweaver style
// first we will capture the style block and assign it to a new var - block
$wad = preg_match("/<style[\s\S]*?style[ \t\n\r]*>/i", $file, $fgg);
$block = $fgg[0];

// wer captures the whole style name and definition into the $hello array
$wer = preg_match_all("/\.[^\.]+?}/is", $block, $hello);

// rest is now the whole style class declaration
// for each value in the array we will loop through the code and swap the styles in
foreach(array_unique($hello[0]) as $rest) {
$rest = trim($rest);
$rest = preg_replace('/\s+/', ' ', $rest);
// now we split the style names and definitions into 2 different arrays
// $h2 is the style name and $h3 is the associated definition
preg_match_all("/(?<=\.)\S+(?=\s*?{)/i", $rest, $h2);
preg_match_all("/(?<=\{)[^}]*/i", $rest, $h3);
$styledef = trim ($h3[0][0]);
$simplestylename = trim ($h2[0][0]);
$clssub = 'class="'.$simplestylename.'"';
$clsrp = 'style="'.$styledef .'"';
$file = str_replace($clssub,$clsrp,$file);
}

Tuesday, November 10, 2009

Replacing tag based class definitions with inline styles

Again, this can be useful for parsing HTML bound for rich text email, where you need to use inline styles -- for example when sending to a gmail account. this will scoop out the styles and plop them into the tag itself, it also will replace double quotes with single quotes for those pesky font familes that include spaces in the name

// PHP 4
// attempt to replace tag based class definitions with inline styles
// add tags to the array to expand the scope

$sar = array('a','h1','h2','h3','h4','p','ul','li');

$i = 0;
$sarsize = sizeof($sar);
while($i<$sarsize){
$tag = $sar[$i];
$pattern = '/(?<='.$tag.'.\{)[^}]*/i';
$style = preg_match ($pattern, $file, $smem);
$attributes = $smem[0];
if ($attributes){
$attributes = str_replace('"',"'",$attributes);
$attributes = preg_replace('/\s+/i', ' ', $attributes);
$attributes = trim($attributes);
$file = str_replace('<'.$tag,'<'.$tag.' style="'.$attributes.'"',$file);
}
$i++;
}
$i = 0;

Monday, August 17, 2009

The 99¢ economy

The Apple store demonstrates how infinite resources drive price down to a convenience fee

The apple app store is a great tool to study pricing effects. Game developers are learning that $9.99 might seem like a fair price, yet by reducing the price by 90%, the net dollar amount of sales skyrocket. When the price is reduced to a sub dollar amount, the potential marketplace expands exponentially. If something is infinitely reproducible for zero cost, the economics get a little nutty, and that's what software developers are beginning to figure out. If you have a popular consumer digital product, It's actually in your best interest to charge as little as possible in order to maximize your sales. The issue many marketing types don't yet get is that in a digital marketplace, the more valuable your product is, the lower it's price — and as the price drops your profits go up, not down.

In a perfect supply and demand economy all digital prices will fall to that of a convenience fee, lets say for example, 99¢. It won't matter what you are selling, whether it's an app that makes your telephone play back fart sounds, or a word processor, or a 3 hour long science fiction movie, a hit record, or even software that allows you to do 3D design and drafting for heavy industry. If it's a popular app or genre, someone is going to undercut you with a better product for a lower price until the price reaches that of a convenience fee. Think Redbox.

The profitability comes from keeping the price intentionally low, yet steadily adding value to the product in order to increase popularity. Would Adobe earn more money by reducing the price of Photoshop from $861.00 to 99¢? — 6 billion humans on the planet? — I bet they would, but until they figure out that in a digital economy price and value have a inverse relationship, I would not bet on it.

Tuesday, April 7, 2009

Replacing CSS styles with inline style for rich email

Ever get frustrated when you use a "dreamweaver" style markup system, just to find that class definitions don't show up in certain email rendering environments?

The trick is to swap the declared classes for inline styles. I found another solution on the web that was way more complex than it needed to be, so here is a simpler way to do it:

note: in PHP and where $file is your HTML code:

// replace dreamweaver CSS class definitions with inline styles
if (preg_match("/class=/i", $file) ){
$wer = preg_match_all("/\.style[^\}]*\{*\}/i", $file, $hello);
foreach(array_unique($hello[0]) as $rest) {// rest is now the whole style class declaration
$rest=trim($rest);
$rest = str_replace("\n"," ",$rest);
preg_match_all("/\.style\S*.(?=\s+\{?)/i", $rest, $h2); // $h200 should now be just the .style45654 part
preg_match_all("/(?<=\{)[^}]*/i", $rest, $h3); // $h300 should now be just the definitions within the style
$styledef = trim ($h3[0][0]);
$simplestylename = trim ($h2[0][0]);
$simplestylename = str_replace('.','',$simplestylename);
$clssub = 'class="'.$simplestylename.'"';
$clsrp = 'style="'.$styledef .'"';
$file = str_replace($clssub,$clsrp,$file);
}
}

Monday, March 24, 2008

BLOCKBUSTED: How a 30 year old assumption created the Blockbuster behemoth by picking Hollywood's pockets.

The year was 1980 and first video players were gaining popularity. A new form of home entertainment had been created. Suddenly the average family could watch Hollywood hits in the comfort of their own homes, anytime they wanted, as many times as they wanted. It was indeed a revolutionary change for the film industry and consumers.

Early adopters paid a stiff price with machines north of $1,000 and individual movies priced at $100-$200 to purchase. For those who were in love with the technology it was an easy decision. The price was high, but it was worth it for a sexy new technology. Everyone assumed owning a Hollywood hit would be a privilege with a high price tag. Superman and Tootsie were multi-hour well-acted epic sagas, not just some BEE GEEs record or a paperback novel. The price was fair and the value was there.

I had a taste of just how cool these machines were; my fifth grade friend's family bought a Betamax machine and the movie Superman. The movie was $189 (in 1981 dollars). That was the only movie the family ever bought.

By 1986 a third of US households had a VCR or Beta machine. By 1988 Sony gave up on Betamax as a viable option to VHS. As late as the mid 1990's VHS tapes directly from distributors were still listed around $90—excluding special promotions for hit movies where direct sales seemed a viable market as long as the price was in the $30-$40 range.

This caused a massive video rental industry to be created. In every town across the country mom and pop stores were charging $2 a night for videotape rentals. Even the local Rite-Aid pharmacy had video rentals.

On almost every street that had small businesses on it, you could find a video rental store. Convenience stores, record stores, supermarkets—they all got in on the action. It's not hard to see why, once the movie was rented enough times, any future rentals were almost pure profit. The math was simple, starting a business was cheap, and no skilled labor or value added services were necessary to be competitive.

US copyright law provides the right of first sale—this allows purchased lawful copies of a work of art to be re-sold, loaned, rented or destroyed, but not mass duplicated for resale. The content creator receives no cut when a video is rented. Effectively, what was happening was that the rental stores were charging a licensing fee for content they did not own—and the two dollars were going to the store owner's pocketbook. No one thought of it this way because consumers were paying two dollars to rent a reel of magnetic tape in a plastic box for one evening.

Why was it so easy to do? Wouldn't it seem that Hollywood would notice this new emerging industry built around its number one product and the amount of cash that was flying around? Hollywood seemed content to be selling a few copies of expensive tapes to the rental businesses and keep their product purposefully scarce. Perhaps they liked the tactics of the Ferrari car company—only sell 1000 cars in North America each year to create exclusivity, and then make the real money on the product licensing deals for the brand. Building Ferrari cars is one thing, but this strategy can not work for a product that can be cheaply duplicated once completed.

By 1989 video rental was clearly a legitimate industry, and like anything else the big profits were attracting corporate investment. Eventually a couple of big public companies began to dominate the video rental business. It was such a profit producing industry that Blockbuster stores were opening faster than chain coffee retailers are today. Blockbuster, with their then-radical "two night rental" policy was amassing a fortune $3 at a time because they understood the value proposition to the consumer—and the movie producers did not.

Eventually movie prices fell to the point where consumers could make the decision to purchase the movie for their collection, or rent the movie for 1/3 the price. Luckily for Blockbuster, the value to the consumer remained in the rental arrangement. It was an entire industry built around a simple mistake: Hollywood's inability to recognize the simple economics of value. The reason that the video rental industry still exists today is that there is no value to the average consumer if he has to pay $20 for the movie. The rental industry essentially corrects this mistake and makes a huge profit that should be enjoyed by the producers themselves.

Hollywood didn't get the formula right.

Blockbuster rents the movie 5 times for $5, and then sells it for $10. What if those same 6 people bought the movie at a supermarket for $3.99 instead of fooling with renting it? If most consumers purchase 2 or 3 new releases on disk, yet rent 40-70 disks in a year, where's most of the consumer cash going? To Blockbuster or Hollywood?

What if Hollywood decided to eliminate rentals altogether and sell to the consumers for the same price? If most disk sales are wholesale to Blockbuster who can extract $35 cash from each disk, why does Hollywood let Blockbuster get fat on its lunch? Perhaps it's because they are holding out to sell $38 Blu-Ray disks? $38 disks are going to be a hard sell when the cost of infinitely reproducible digital goods always drops to near zero on a long enough time line.

Here is the thing that Hollywood has trouble admitting: Unlike audio disks most people will not watch a movie more than twice, so by purchasing the movie they are overpaying for the experience of viewing it. Because the product is only valuable on the first or second uses, it can be thought of as a toy that becomes unwanted in 2 to 4 hours. Feature film disks are actually less valuable than audio disks to the average consumer.

Even though it costs $250 million to produce a movie, it's only worth $4 to the average consumer. Hollywood tries to market their disks as collectible, durable goods because of the prestige—but a modern economist analyzing the situation recognizes that disks are actually in fact disposable commodity items not too dissimilar to plastic razors. Audio disks on the other hand are worth much more because they are much more durable.

Consider the new world of digital movie downloads. Consumers pay $3-$6 to download a digital file to a computer or computer-like device and then have a given amount of time before the movie expires. Some think that the expiration mechanism is there to spur hard copy sales, or to deter file trading, but the real reason it's there is to prop up the artificial value of the movie. If the movie does not expire from the hard disk, consumers have effectively paid $3.99 to "own" the movie. If it remains on the hard disk the line between owning and renting would blur. Would consumers watch The Fast and the Furious 75 times on their computer if it did not eventually erase itself? Would Hollywood somehow be losing money if that happened? The answer is probably not, but the expiration mechanism remains as an un-natural way to add value to physical disc ownership by limiting the electronic product.

Movie producers need to embrace the fact that their products are disposable. Casual movie fans don't buy every movie they want to see, they rent. They line up every Friday night to cram Blockbuster's cash registers full $4.50 at a time.

Hollywood is choosing the $50 bill instead of the 5,000 nickels. Imagine going from 15,000 paying customers to 300,000,000 paying customers? That's exactly what the $3.99 new release would do. The profit-grabbing physical video rental business would be eliminated overnight.

Bye-Bye Netflix and Blockbuster, thanks for pointing out Hollywood's mistake.