Checking in Flex/AS3 for corrupt JPGs (invalid images)

-

Thursday, February 25th, 2010

In a recent project we were running into problems with corrupt jpg images that end users were uploading. We wanted to check on the Flex side if these images were invalid before even uploading them. (We do check for image validity on the server side as well, but why waste the upload time?)

Here is a function that will take in the byte array for a jpg and tell you if it is valid or not. Keep in mind this doesn’t check everything, just that we have a file that has the correct EOI segment header at the end.

Update 3/24/10: I added one more sequence of valid bytes

protected function isValid(bytes:ByteArray):Boolean
{
	var toReturn:Boolean = false;
 
	//take the file name and check it against jpg extensions to make sure it is a jpg
	var namePieces:Array = file.name.split(".");
	//I'm getting the file extension this lame way, bc for some reason file.type is null
	var extension:String = namePieces[namePieces.length -1];
 
	//if it is indeed a jpeg then we want to check the validity
	if(extension.toLowerCase() == 'jpg' || extension.toLowerCase() == 'jpeg')
	{
		//move to the second to last position in the bytearray
		bytes.position = bytes.bytesAvailable - 2;
 
		//get the last two bytes
		var secondToLastByte:uint = bytes.readUnsignedByte();
		var lastByte:uint = bytes.readUnsignedByte();
 
		//if the last two bytes don't match the EOI segment header at the end of the file
		//then we know it is invalid
 
		if((secondToLastByte == 255 && lastByte == 217) || (secondToLastByte == 217 && lastByte == 0))
		{
			toReturn = true;
		}
	}
	else
	{
		toReturn = true;
	}
 
	return toReturn;
}

Inspiration for this bit of code came from http://stackoverflow.com/questions/198438/efficiently-detect-corrupted-jpeg-file

360 Flex

-

Monday, February 1st, 2010

Rain is a big fan of the 360 Flex conferences. We send developers every time, and have noticed the conference quality increase with each year. We are pleased to announce that we are sending 5, count them 5 speakers.

If you are considering going, I highly recommend taking part. If no other reason than to see our beautiful faces. Here is the link to register.

Here are the individuals we are sending, as well as the sessions they are teaching:

badge-2
Speaker: Aaron Hardy
Title: Queue N Cache
Description: Take control of service calls by creating your own queue and dynamically shifting priority based off user interaction. Load what users are looking at first and and delay the rest for later. Show progress indicators in multiple locations for a single request. Once loaded, cache images in such a way that they can be displayed immediately anywhere in the app.

badge-2
Speaker: Bryce Barrand
Title: Golden nuggets: How to find and keep top developers
Description: Part I. Even in a down economy, finding top developers is quite a task. For the most part, good people have solid jobs they love. Should you cross train? Pay hefty fees for head hunters? Monster.com? In this session we will go over a couple of options, and what we’ve found to be successful for procuring those “golden nugget” employees.

Part II: Once you have them, what makes them stay? How much does company culture make a difference? How about work load? What type of environment is cost effective for you as the employer and awesome for everybody around? We’ll also cover tips on keeping developers happy, and around for years.

badge-2
Speaker: Garth Braithwaite (teaching 2 sessions)
Title: Flex 101
Description: Get up to speed on Flex quickly.  We’ll be taking a full day of training to cram as much Flex 4 goodness into your head.  This training is designed for those who have never used Flex.

Title: Your Flex App Looks Like Poo
Description: There is absolutely no excuse for not skinning your Flex 4 applications.  We will be exploring skinning Workflows, skin requirements, and creating custom preloaders.  Ultimately overhauling the interface.  Although user interface design principles will be discussed, this session will not teach you how to design.

badge-2
Speaker: Chase Brammer
Title: Analytics Throwdown
Description: Clients will ask, and you will be forced to choose your analytics weapon. Learn about Adomniture’s and Google’s analytics tools and how you can use them to drive business. The session will be divided up into three sections. First, the high level details about the qualities and business benefits of each. Second, a simple walk through of how to use the tools. And last, how to implement and deploy those tools in your applications.

badge-2
Speaker: Gary Rogers
Title: Automated Build and Deployment Processes
Description: This session would encompass the often misunderstood methods for automating flex build and deployment cycles. Several options and examples would be concisely presented including java ant, php phing and others, as well as how to wield the power of the command line flex sdk. I would present a brief tutorial on how to get started with these methods. Also, a sophisticated GUI based build server concept would be discussed. I would also weigh the pros and cons of nightly builds and scheduled deployments and how these impact various architecture phases of an application. Also arguments discouraging the use of SVN/CVS for deployments would be presented.

In case you missed it at the beginning of the post, here is the link to register.

Insatiable for Social Media

-

Thursday, October 1st, 2009

Everyone’s yammering about social media these days. It would be hard to name a client who’s brought a project to our door over the past year who had not asked that we integrate some sort of social media component with said project. One of our recent favorites was an RFP for an extremely large government initiative that insisted this blandly institutional program be outfitted with all the trendy social media accessories to make it capture the public’s imagination and spread like wildfire. We came up with some fun ideas, but all the same, we couldn’t really imagine the desired result actually happening. Why? Because, inherently, the message at the heart of it all just did not feel like it was worth getting excited about. In our opinion, no one was going to Facebook or tweet about this bad boy. From a social media perspective, we saw this as a very earnest effort to polish a marketing turd.

The fact is, like traditional marketing and advertising efforts, some social media campaigns work, and some don’t. And even if a campaign generates the desired buzz, where does that buzz direct you, and ultimately, does it effectively serve the bottom line? I recently read an article that made some interesting comparisons between various social media initiatives.

For example:

Have you ever had the opportunity to “elf yourself”? If you recognize that phrase, you’ve probably played with the engaging little online holiday application that allows you to personalize a troupe of dancing elves with photos of yourself and/or family and friends. Most likely you, and about 150 million others, emailed your brilliant creation to your circle of friends, and received a few of theirs in return. Lots of fun, and a social media phenomenon. The company that sponsored and paid for the application saw some impressive results for their investment: it has been the most-visited holiday greeting site two years in a row and netted 200 million visitors in 2007 alone.

Now here’s the question: do you know the name of that sponsor company? Chances are, you don’t. Sorry, Office Max. Despite all the activity engendered by the application, Office Max saw it’s sales drop 7.5 percent during last year’s holiday season and has posted losses over several quarters.

Now, when you hear the phrase, “That was easy,” or see an image of a red “Easy” button, what company do you think of? Staples probably bubbles right to the surface. Their “Easy” campaign has consistently and effectively communicated its core message – that Staples efficiently helps you solve problems. The result? From a social media standpoint, that message has become part of the social consciousness, ranking right up there with phrases like “I’m loving’ it.” and “Got milk?” They’ve sold gads of actual souvenir “Easy” buttons which reinforce the campaign in a very tangible way. And most importantly, since Staples remains solidly in the black, the economic results have been noteworthy as well.

To be effective, a social media initiative needs to have a strong connection to its brand. Elves are cute, but after all the ooo-ing and aww-ing, how do you make the connection back to office supplies? And how does Office Max in particular fit into that scenario? Fact is, it doesn’t. Office Max got a lot of fizz for their efforts, but no substance, and no resonance for their brand. Staples, by contrast, continues to get meaningful mileage out of their campaign.

As we move forward in putting more and more social media campaigns together, it would be smart to always do an “authenticity check”, and ask ourselves whether or not the initiative connects to the brand in a meaningful, memorable way. Additionally, let’s ask the even more basic question: does social media provide the right channel for this project? Will people care about the funny, flashy campaign but forget the brand behind it? Just because everyone’s yammering about social media doesn’t mean every campaign should use it.

Rain Finalists for Adobe MAX Award

-

Monday, September 28th, 2009

One of our projects, PianoMarvel, is a finalist for an Adobe MAX award under the category of education. Help us out by voting for us here.

Calculating Image Resolutions in Flex

-

Sunday, September 20th, 2009

Custom book builders are great Rich Internet Applications that we’ve made at Rain. One core component of custom book builders is allowing users to upload their own photos. The most common user error is uploading and using a photo that cannot be printed at a high quality print resolution. It is our job to let the user know if the image he or she has selected for a particular ImageWell (a rectangle where a photo can be placed) can be printed.

Basics of printing

Printers print according to dpi (dots per inch). Say a 1200 px x 1800 px image is printed onto a 4″ x 6″ sheet of paper. The dpi would then be:

  • width: 1200 px / 4 inches = 300 dpi
  • height: 1800 px / 6 inches = 300 dpi

Print resolutions can vary anywhere from 150 dpi (low/medium quality) to 300 dpi (high quality) and up.

Our Example

First we need to define two variables:

  1. Final print resolution dpi
  2. Warning dpi

For this example we will use a final print resolution of 300 dpi and we will show a warning if the image resolution is lower than 200 dpi. The user has uploaded a low resolution 400 x 500 photo to our photo book application. The user has placed the photo into an ImageWell that is 1200 x 1200 (square). Then the user scales the image to 200% which crops the photo and lowers the dpi.

(more…)