Greyscale an image

Now that I’ve got all my icons into the image library (see my recursive image library creation post) I wanted to limit the number of times I need to go back to an image editor to mess with the original files to create variations. One of the most common variations for button icons is the greyed out disabled icon so I wrote a little rev plugin to greyscale the selected images.

The plugin uses the following command:

<code>on greyscale pImageID
   local tImageData, tRed, tGreen, tBlue, tGrey, tOffset,tWidth,tHeight
   lock screen
   put the width of pImageID into tWidth
   put the height of pImageID onto tHeight
   put the imageData of pImageID into tImageData
   repeat with tOffset = 0 to tWidth *tHeight * 4 step 4
      put charToNum(char tOffset + 2 of tImageData) into tRed
      put charToNum(char tOffset + 3 of tImageData) into tGreen
      put charToNum(char tOffset + 4 of tImageData) into tBlue
      --correction for better greyscale from Mark 
      --put (tRed+tGreen+tBlue) div 3 into tGrey
      put (tRed*30+tGreen*59+tBlue*11) / 100 into tGrey
      put NumToChar(tGrey) into char tOffset + 2 of tImageData
      put NumToChar(tGrey) into char tOffset + 3 of tImageData
      put NumToChar(tGrey) into char tOffset + 4 of tImageData
   end repeat
   set the imageData of pImageID to tImageData
end greyscale</code>