Friday, February 10, 2012

JavaScript for Photoshop - When Macros Aren't Enough

This2That Tile Sample

A few years ago, a fellow named Brian Dorn got in touch with me. He was working on his doctoral dissertation at Georgia Tech and he needed participants. I met him in Atlanta and found out that his study was about scripting with Photoshop. That was the first I'd ever heard of Adobe Photoshop Scripting.

A few weeks ago when I started working on a new word game This2That for Mobile Magic Developers, I needed to generate 38 tiles with letters, numbers, and punctuation. The task was tedious and the macros just couldn't make it any easier. Then I realized I had the embossing all wrong and I had to start over!

Frustrated, I tried to think of a better way. I remembered Brian Dorn and I started looking into this Adobe Photoshop JavaScript thing. I was very pleased when 15 minutes of script became an easily reusable tile generating utility. Now, I can take any PSD, open it up, select any text layer, and have the script generate a PNG for each letter I need

I thought this little known feature would make for interesting reading for both programmers and designers so here's my script:

// call the method that does all of the work
main();

// wrap the code in a method to make it easier to debug
function main() {

 // make sure you're working in a document and have a text layer selected
 if (!activeDocument || !activeDocument.activeLayer || activeDocument.activeLayer.kind != LayerKind.TEXT)
 {
   alert("Please select a document and a target text layer.");
   return;
 }
 
 // set up some information about the current file
 var textLayer = activeDocument.activeLayer;
 var path = activeDocument.path;
 var fileName = activeDocument.name;
 
 // remove the extension on the file name
 var extensionPosition;
 if (extensionPosition = fileName.lastIndexOf('.'))
  fileName = fileName.substr(0, extensionPosition);

 // get a good place to put the file
 var outputFolder = Folder.selectDialog("Select a target folder.", path);
 
 // set up the letters we want images for
 var characterMap = [
  ["question", "?"]
 ];
 
 // and add the lowercase alphabet and numbers
 characterMap = characterMap.concat(getAsciiRange(97, 26), getAsciiRange(48, 10));

 // for each character, update the selected text layer and save a file
 for (var i = 0; i < characterMap.length; i++)
 {
   var character = characterMap[i][1];
   var fileSuffix = characterMap[i][0];
   
   textLayer.textItem.contents = character;
   
   var file = new File(outputFolder + "/" + fileName + "_" + fileSuffix + ".png");
   var options = new PNGSaveOptions();
   options.interlaced = false;

   activeDocument.saveAs(file, options, true, Extension.LOWERCASE);
 }
};

// a little helper method to make a range of letters and their
// filename extensions
function getAsciiRange(from, count) {
 var result = [];

 for (var i = 0; i < count; i++)
 {
  var character = String.fromCharCode(i + from);
  result.push([character, character.toUpperCase()]);
 } 
 
 return result;
}
 

Wednesday, February 8, 2012

Small Business, Big Difference - NBCF Approved

National Breast Cancer Foundation Banner

Last week I wrote a blog post introducing our Small Business, Big Difference program to raise money for the National Breast Cancer Foundation. This week, I got in touch with them and they gave us the go-ahead to run the fundraiser. We're very excited about the news!

So, we want to make sure you know how you can help! There are three ways that you can help us raise money to give to the NBCF.

Spread the Word


Get the App

  • Download the Jane Austen Quote of the Day Widget application.
  • Enjoy the application! We'll donate all ad revenue from the Jane Austen widget during the promotion period of Sunday, February 12th, 2012 and ending Saturday, February 18th, 2012.
  • If you love the app, buy the Jane Austen Widget Upgrade for less than a buck and we'll donate that too!

Want to Give More?

You're more than welcome to give as much as you want! You can visit the Mobile Magic Developer's Small Business, Big Difference for NBCF fundraising site powered by StayClassy.

If you have any questions at all, please feel free to contact us through our facebook page or twitter account. We'd love to address any concerns you may have.

Saturday, February 4, 2012

National Breast Cancer Foundation - Small Business, Big Difference

National Breast Cancer Foundation Banner

James and I recognize that we get a great deal of benefit out of writing mobile applications with Mobile Magic Developers. We enjoy the time together, the camaraderie, the learning experiences, and the opportunity to bring a little joy to a much larger audience. Along the way we've had a lot of support from friends, family, and the numerous customers who've downloaded our apps.

We wanted to find a way to give something back as an enthusiastic "Thank You" from the Mobile Magic Developers team to you. We've decided we're going to try something we call Small Business, Big Difference. Periodically, we're going to choose one of our applications and for a period of time, all proceeds from that application will be donated to a charitable organization. That includes sales and ad revenue.

For our inaugural Small Business, Big Difference attempt, we've decided that we'll donate all revenue generated by our Jane Austen Quote of the Day Widget available on the Android market to the National Breast Cancer Foundation. We've even added a new background for your widget just for this occasion!

Why the National Breast Cancer Foundation

We reviewed dozens of charitable organizations dedicated to promoting breast cancer research, helping breast cancer survivors, and comforting those fighting with breast cancer today. We considered each organization's rating on Charity Navigator and the NBCF scores on Charity Navigator were remarkable including a maximum score for accountability and transparency, 83.1% of revenue dedicated to program expenses, and a solid plan for growth.

We also felt strongly for the foundation's mission to save lives through early detection by providing education and mammography, particularly to women in need. The NBCF works with almost 100 clinics in all 50 states to provide free mammograms and diagnostic services to underserved women. Each sponsored facility is required to have the capacity to provide continued treatment to women after an abnormality is found or breast cancer is diagnosed.

How You Can Help

Your role is easy. Download the Jane Austen Widget from the Android market, use the "Share" buttons to share your quotes on Twitter and Facebook, encourage your friends to get the app. If you really like it, purchase the Jane Austen Widget Upgrade, the ads will go away and we'll donate the proceeds from your upgrade too.

The program will run for 1 week starting Sunday, February 12th, 2012 and ending Saturday, February 18th, 2012. Download the free application today and help us spread the word about the application and the promotion. The more people who have the free app, the more ad revenue we'll be able to donate. Don't buy the upgrade though until the week of Valentines Day so we can donate your upgrade too.

We hope to make this program a huge success because we're already looking into our next charity (hopefully promoting children's literacy with proceeds from our educational apps for kids). We're excited about this opportunity and with your help we can prove what a big difference a small business can make.