how do I convert CMYK to RGB?

Hi,
i’m trying to do a script that checks the color space of an image, and the determines if it has to be converted to RGB or not.
i only work with CMYK or RGB, but i need all of them in RGB. so, i want Image Events to check for the color space, and then tell photoshop that if it is a CMYK image, to change it to RGB…
the thing is I can’t even get Image Events to display a dialog with the color space… i’m really stuck…
i’ll appreciate any help.
thanks.

marto.

PS: please consider i’m a total newbie, and the only thing i understand is applescript… nor automator or shell or anything else… thanks!!!

This will get the color space for a given image… from there you could you decide wether you need to send the image to Photoshop for processing depending on the value of cSpace.

set theImage to choose file
try
	tell application "Image Events" to set cSpace to {color space} of (open theImage)
on error errrMessage
	display dialog errMessage
end try
set TheDoc to choose file
set ConvertMe to false
tell application "Image Events"
	set theFile to open TheDoc
	if color space of theFile is not CMYK then set ConvertMe to true
	close theFile saving no
end tell

if ConvertMe is true then
	tell application "Adobe Photoshop CS2"
		activate
		open TheDoc
		if mode of document 1 is not CMYK then change mode of document 1 to CMYK
		close document 1 saving yes
	end tell
end if

ok. thank you both. that worked great to do de convertion…
but things weren’t thant simple… ( i thought they would… fool of me!!! )

the process of converting the image is to be done without altering the original file, and also as image events is creating a preview file and a thumbnail.
i thought that the best and fastest thing to do is to create with image events the preview file, open that one with photoshop (if it is in CMYK), convert it, and then use that preview file to create the thumbnail file.
this is because the original image wieghts from 5 to 30mb, but the preview is only 500 to 800kb… so, convert the preview is faster than the original… and edit the preview to create the thumbnail is also fastest.

well… here is the part of my code that processes the images

source_file is an alias to the origianl file.
pwg is the preview, and tn the thumbnail…

on process_pwg(source_file, file_name, pwg_folder, tn_folder)
	try
		set the pwg_path to ((pwg_folder as string) & file_name) as string
		set the tn_path to ((tn_folder as string) & "tn_" & file_name) as string
		set convertMe to false
		with timeout of 180 seconds
			tell application "Image Events"
				launch
				set this_image to open file (source_file as string)
				if color space of this_image is CMYK then set convertMe to true
				scale this_image to size 400
				save this_image as JPEG in file pwg_path with icon
				close this_image
			end tell
			if convertMe is true then
				tell application "Adobe Photoshop CS"
					activate
					open file (pwg_path as string)
					change mode of document 1 to RGB
					close document 1 saving yes
				end tell
			end if
			tell application "Image Events"
				launch
				set this_image to open file (pwg_path as string)
				scale this_image to size 120
				save this_image as JPEG in file tn_path with icon
				close this_image
			end tell
		end timeout
	on error errormsg
		display dialog errormsg buttons {"ERROR PROCESS"}
	end try
end process_pwg

my problem is that it doesn’t work… photoshop says that it can’t find the file… but i don’t know why, because by that part of the code, the preview is already scaled and saved…

could it be a matter of real time that it takes Image Events to save the file??? (remember is a very large file)
if it is so… what can i do?

well, thank you very much.

marto.

since you are going to open the file I would do all the processing in PhotoShop to simplify the handler and debugging.

If this task is going to be done a lot you may want to look at ImageMagick as well. I would bet that it would be faster.

well yes… that would be a lot easier for me to write, but since the amount of files is huge, and the size of them is also huge, and the computer the script would be ran is a G4 733mhz, my boss and I thought we could optimize the process by mixing it up with Image Events…
any other suggestions are wellcome though!

THANKS JEROME!!!

marto.

ImageMagick… I was told to use it… but, honestly, i don’t know how…
i’ve been looking to the commands on the imagemagick site, but i can’t figure out how to use it within applescript…
i’ve also seen that it’s used with “do shell” or something like that, but i have no idea of what that is…
if you could give me some pointers for me to begin with using imagemagick from applescript, i 'd appreciate it!!!

thanks guys.

marto.

If I understand the process you are scripting correctly then you are doing the following:

a. making a copy of the file
b. down-sampling the image to a smaller size for preview (image events)
c. converting that image if needed (photoshop)
d. duplicating the file
e. down-sampling the image to thumbnail size (image events)

so in the end you have:

  1. the original file
  2. preview file
  3. thumbnail file

Is this correct? If so I would use image events for the first down-sampling, open that file in PhotoShop for any conversions that are needed and save. Then with the file still open down-sample again and save as to a new file for your thumbnail.

You could save a lot of time by swapping out the photoshop cmyk → rgb code to

tell application "Rgb_r"
	open this_image
end tell

The “Rgb_r” app. is a simple Automator action app.

In Automator go to Preview Actions.

select “Apply ColorSync Profile to Images” action.
You will be asked if you want to work on a copy of the image by adding a copy action the first time you drag this action over.(I choose not to )

In the Profile selection go to ‘Display’ and choose thr RGB profile you want.
I do not tick preserve colour space.
As Seen Here

Save the workflow as a Application - name “Rgb_r”

I have found this is much much faster than opening the image in PS.

I am doing something similar in Illustrator, but I am converting to SWF when done. I have a variety of file types running through the script, and I am going to have to keep the processing in Illustrator. When I try to change the color space in Illustrator CS3, I get an error. The dictionary only addresses color mode for new documents, but I need to change it.


tell application "Adobe Illustrator"
	activate
	tell front document
		set color space to RGB
	end tell
end tell

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 2.0.0.3
Operating System: Mac OS X (10.4)

If you are changing the colour space before you convert to SWF,

You could bypass AI, and look at the man page for sips (scriptable image processing system)

Sips allows you (in most cases) to change the colour space without opening the file.

Example:

set thePicture to quoted form of POSIX path of (choose file)
do shell script "/usr/bin/sips -m '/System/Library/ColorSync/Profiles/Generic RGB Profile.icc' " & " " & thePicture