• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting a color value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting a color value


  • Subject: Re: Getting a color value
  • From: Stan Cleveland <email@hidden>
  • Date: Mon, 21 Jul 2008 15:29:39 -0700
  • Thread-topic: Getting a color value

On 7/21/08 6:32 AM, "Jesse Almanrode - JA Computing" wrote:

> I am currently writing a script for Photoshop that needs to sample the color
> on an image.  What I am looking to do is run a 5 x 5 pixel average sample in
> the four corners of the document (to determine if they are pure white).
> However, there does not appear to be a way to do this with AppleScript.
> Anyone know how to do this or if it can be done?

Jesse,

The code below will make a 5x5-pixel selection in each of the four corners
and get the average value of each pixel in the selections. You can tweak as
needed, but that should get you going in the right direction.

HTH,
Stan C.


tell application "Adobe Photoshop CS3"
tell current document
set {l, t, r, b} to bounds of layer "Background"
select region {{l, t}, {l + 5, t}, {l + 5, t + 5}, {l, t + 5}}
set upperLeftValues to my getAvgValue()
select region {{r, t}, {r - 5, t}, {r - 5, t + 5}, {r, t + 5}}
set upperRightValues to my getAvgValue()
select region {{l, b}, {l + 5, b}, {l + 5, b - 5}, {l, b - 5}}
set lowerLeftValues to my getAvgValue()
select region {{r, b}, {r - 5, b}, {r - 5, b - 5}, {r, b - 5}}
set lowerRightValues to my getAvgValue()
end tell
end tell

on getAvgValue()
set avgColorValues to {}
repeat with chan in {"Cyan", "Magenta", "Yellow", "Black"}
tell application "Adobe Photoshop CS3"
tell current document
set histoList to (histogram of channel chan) as list
end tell
end tell
set histoList to reverse of histoList
set numPixels to 0
set totalValue to 0
repeat with i from 2 to 256 -- exclude item 1 (pixels with zero value)
set x to contents of item i of histoList
set numPixels to numPixels + x
set totalValue to totalValue + (x * i)
end repeat
try -- round to 1/10th percent
set end of avgColorValues to (round (totalValue / numPixels / 0.256)) / 10
on error number -2701 -- division by zero
set end of avgColorValues to 0.0
end try
end repeat
return avgColorValues
end getAvgValue


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Getting a color value (From: "Jesse Almanrode - JA Computing" <email@hidden>)

  • Prev by Date: Using apple script in PackageMaker
  • Next by Date: Controlling Apps
  • Previous by thread: Re: System Events XML Suite - how to add / delete elements and attributes?
  • Next by thread: Using apple script in PackageMaker
  • Index(es):
    • Date
    • Thread