Apr 14, 2010

Nice Url in AS3

Feeling generous today, here you go.
(Made to include nordic names)

public static function niceUrl(s:String):String
{
 s = s.toLowerCase();
 s = s.replace(/^\s+|\s+$/g, "");
 s = s.replace(/[_|\s]+/g, "-");
 s = s.replace(/[øöõóò]+/g, "o");
 s = s.replace(/[åäáàãâ]+/g, "a");
 s = s.replace(/[ëéèê]+/g, "e")
 s = s.replace(/[^a-z0-9-\/]+/g, "");
 s = s.replace(/[-]+/g, "-");
 s = s.replace(/^-+|-+$/g, "");

 return s;
}

Mar 17, 2010

Key.isDown(), where did you go?

Got a bit stumped when I realized that multi-keystroke handling was totally removed from AS3. The rabid game programmer in me worked up a little steam while it scurried about the internet looking for a solution. The alternative isn't acceptable, you can't make games without multiple buttons pressed at the same time.

Found a bunch of solutions to this problem, all of them over 100 lines in length. How hard can this problem be?

package Extrude.Utils 
{
 import flash.events.KeyboardEvent; 

 public class Keyhandler
 {
  protected static var _keys:Array = new Array(126);

  public static function onKeyDown(e:KeyboardEvent):void
  { _keys[e.keyCode] = true; }

  public static function onKeyUp(e:KeyboardEvent):void
  { _keys[e.keyCode] = false; }

  public static function isDown(key:uint):Boolean
  { return (_keys[key]); }
 }
}

Feb 20, 2010

Beautiful girls and nice furniture

Just woke, fiddling about with a cup of coffe and feeling good about myself. Had a great time working the last crazy hours of a project that is launching next week.

This is somewhat of a sneak peak, I hope that no one gets their panties in a bunch about it.



Skaargarden.com

It was a really long time since i saw some quality material put in the pipe. Hope that they fare well in todays competitive market.

Jan 24, 2010

Announcing: DropEnc


The last couple of days I've researched the possibility to encode video based on feedback from FFMPEG in AIR. The upcoming desktop application improvements in the AIR 2.0 Beta makes this a possibility.

For once, something that started out as me fooling around in Flex Builder that actually worked. My goal with this encoder is to remove all the technical aspects of video conversion and make it profile based, or just: "Make it simple stupid."

Jan 18, 2010

Leaping headfirst into ExtendScript 2.0

Today we ran into somewhat of a problem at my job. One of our clients had stuffed a server chuck-full with uncompressed TIFF-images. The payload weighed in at the modest amount of 10GB.

Our ability to deliver a somewhat stable way for our customers to deliver content to us vanished, as the veritable meat-pile of images just sat there, customer-satisfaction-blocking us all afternoon.

So i whipped up a quick way for me and my co-workers to quick batch those images into leaner shape.

What we needed for web availability was no more than 1280px-sized images and RGB (sRGB) images.


/////////////////////////////////////////////////////////
// Extrude Weightcutter, v1.1, Extrude Interactive, 2010
// Author: Sven-Erik Jonsson, svenerik@extrude.se
/////////////////////////////////////////////////////////
bringToFront();

var oldUnits = preferences.rulerUnits;
var startDisplayDialogs = displayDialogs;

preferences.rulerUnits = Units.PIXELS;
displayDialogs = DialogModes.NO;

var files = File.openDialog('Choose files to resize', '*.*', true);

if (files)
{
var userImageSize = prompt('Target image size','Enter image size');
var targetImageSize = (!isNaN(parseInt(userImageSize))) ? parseInt(userImageSize) : 1280;

jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 8;

for (var i = 0; i < files.length; i++)
{
var currFile = files[i];
if (currFile.exists)
{
open(currFile);

try
{
if (activeDocument.mode != DocumentMode.RGB) activeDocument.changeMode(ChangeMode.RGB);
if (activeDocument.bitsPerChannel != BitsPerChannelType.EIGHT) activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;

activeDocument.flatten();

try { activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.PERCEPTUAL, true, true); }
catch(e) {}

var portrait = (activeDocument.height > activeDocument.width);

if (!portrait) activeDocument.resizeImage( targetImageSize, null, 300, ResampleMethod.BICUBIC );
else activeDocument.resizeImage( null, targetImageSize, 300, ResampleMethod.BICUBIC );

var asCopy = (activeDocument.name.toString().indexOf(".jpg") > -1);

activeDocument.saveAs(activeDocument.path, jpgSaveOptions, asCopy);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
catch(e)
{
alert(e);
}
}
}
}

// Leave no crap behind
displayDialogs = startDisplayDialogs;
preferences.rulerUnits = oldUnits;
purge(PurgeTarget.ALLCACHES);

Download Script

Installation

Put the script in:
Program Files > Adobe > Adobe Photoshop (CS-version) > Presets > Scripts

Restart Photoshop if needed

Activate from:
File > Scripts > ex_weightcutter

Use with caution around jpeg files.