Convert CMYK images to RGB, web sized images

Does anyone know of a way, without using Photoshop, to convert CMYK images to RGB and knock the resolution down to 72x72?

Here’s the situation. We are a newspaper and, of course, all color images are in CMYK. We want to get them to the web, automatically. I have written an action in Photoshop that processes the images into RGB 600 pixel-wide, 72 dpi images. But our image folks have enough to do already. I’m looking for a way to script it on a stand-alone box with little or no add ons.

It appeared that Image Events would be the answer, but either it won’t change color space or I just don’t know how to make it do it. I’ve been able to get it to scale the image correctly, but can’t figure out how to get it to convert CMYK to RGB or to knock the resolution down. Either it won’t do that or I just can’t figure out the syntax (grammar?). I’ve searched the forums for Image Events and have not found the answer.

I’ve tried Graphic Converter, but can’t get the batch to work on a consistent basis. I’ve emailed the developer, but he’s been working on a major new version that hit in the middle of this project and he’s been very little help. Not being critical, just stating a fact.

I tried iMagine Photo, but could find no way to change the color space from CMYK to RGB.

I have searched the OSAX area of this site, but either I missed it or there’s nothing there that will help me do the conversion.

I don’t want to impose on someone to write my script for me, just point me in the right direction.

Thanks.

Don

Model: MacBookPro 17
AppleScript: 1.10.7
Browser: Safari 3.03 (522.12.1)
Operating System: Mac OS X (10.4)

ColorSync will convert AND let you be very specific if necessary. Check out the ColorSync Scripting Dictionary. Apple also has included a sample script with the OS called “Match to CMYK” that you can use for reference.

A quick look at the dictionary shows that resolution in Image Events is read only. I haven’t used iMagine Photo other than a quick try a while back, but I see that it scales AND supports some ColorSync.

When all else fails“ ImageMagick

-N

Hi Don,

this should do it (according to the sips man page)


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' -s dpiHeight 72.0 -s dpiWidth 72.0 " & thePicture

but unfortunately on my machine the color space conversion will be done, the resolution change won’t

To be honest, doing a Batch job with your Photoshop action is the answer. We do something similar here and just do them in large batches and let Photoshop work it’s magic. Of course, it could be argued my users are fairly saavy and know enough not to split such hairs. A Batch Photoshop job is so much faster than one-at-a-time, and even one-at-a-time with an Action is so much faster than manual, that anything faster is splitting hairs. :wink:

Do you not want Photoshop in the equation because you don’t have Photoshop? Or is there some specific reason to avoid AppleScript controlling Photoshop? Even without Photoshop Actions, you can create very speedy JavaScripts (via Adobe’s ScriptListener plugin) that AppleScript can then kick-off and just “use” Photoshop. Even faster than using AppleScript to set-off an existing Action, near as I can tell. A little cryptic, but I can walk you through the basics of using ScriptListener if you want.

This works for me in Terminal (copied from Script Editor’s event log):

/usr/local/bin/convert -colorspace RGB -density 72x72 -resize 72x72 '/Users/bruce/Public/Test/lcc.jpg' '/Users/bruce/Public/lcc.jpg'

However, it doesn’t work in this form:

choose file with prompt "Make web-sized images from these files:" with multiple selections allowed without invisibles
set sourceList to result

choose folder with prompt "Save web-sized images to this folder:"
set outputFolder to POSIX path of result

repeat with thisItem in sourceList
    do shell script "/usr/local/bin/convert -colorspace RGB -density 72x72 -resize 72x72 " & ¬
        quoted form of POSIX path of thisItem & " " & ¬
        quoted form of (outputFolder & name of (info for thisItem))
    --> error "convert: no decode delegate for this image format ."
end repeat

Edit: This requires ImageMagick.

Hi Bruce,

this is doubtlessly the best solution, but it requires ImageMagick installed :wink:

Who doesn’t have ImageMagick installed? :rolleyes: I added a link to my previous post.

I’m not too hot with shell scripting, but this clunkyness using StefanK’s Image Events idea worked on 10.3. However a slightly changed version (parsing the stdout differently) did not work on 10.4. It didn’t take to the resampleHeightWidth (that’s the “-z” function).

Is there a cleaner way to get the properties?

-- define dpi to downsample to
set rDPI to 72.0

set thePicture to quoted form of POSIX path of (choose file)

-- gets file properties
set x to (do shell script "/usr/bin/sips  -g all  " & thePicture)

-- sets file properties as list
set theW to every paragraph of x

set theoldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ": "
-- parses measurements
try
	set pxW to text item 2 of item 2 of theW as real
	set pxH to text item 2 of item 3 of theW as real
	set dpiW to text item 2 of item 6 of theW as real
	set dpiH to text item 2 of item 7 of theW as real
	-- does math	
	set HeightInInches to pxH / dpiH
	set newHeight to HeightInInches * rDPI as real
	set WidthInInches to pxW / dpiW
	set newWidth to WidthInInches * rDPI as real
on error
	set AppleScript's text item delimiters to theoldTID
end try
set AppleScript's text item delimiters to theoldTID

-- converts color and switches dpi to rDPI
do shell script "/usr/bin/sips -m '/System/Library/ColorSync/Profiles/Generic RGB Profile.icc' -s dpiHeight " & rDPI & " -s dpiWidth " & rDPI & " " & thePicture

-- rescales to original dimensions while staying rDPI
do shell script "/usr/bin/sips -z " & newHeight & " " & newWidth & " " & thePicture

-N

Thanks everyone. I’m currently digesting and combining all these suggestions and I have something kind-of working. I’ll report back in a day or so to let everyone know how it’s going. You folks are awesome.

Don

Ok Everyone. I’ve gotten it to work. I’m still working on moving the images to the folder I want them in, but this part of the script works correctly, at least on my system (MBP 17 Core Duo, OS X 10.4.10 all current). When I get everything working exactly the way I want it, I’ll post it.

I’ve left all my comments in because a) when I come back and look at the script in a couple of weeks, I want to know why I did what I did, and b) I learned a lot in this exercise and wanted to share that knowledge.

If you see anything that could stand improvement, please post a reply.

--This script convert CMYK high-resolution jpgs to RGB and web resolution either by selection in a dialog box or a folder action, depending on what lines are commented out. Output is jpg.

--For this to work, you must install ImageMagick, available at http://www.imagemagick.org/script/binary-releases.php#macosx. The convert application is a part of that installation.

-- NOTE: THIS SCRIPT REPLACES THE ORIGINAL FILE WITH THE CONVERTED FILE IN THE ORIGINAL FOLDER.

---------------------------------------------------------------------------------------

-- Uncomment the bottom line in this section to have the script ask users which file to process. (Be sure to comment out the parts of the next section which make the script run as a folder action. Those parts are marked with a --<)
-- (Choose file) generates a dialog box which allows you to select a file. You must set the variable to the POSIX (real UNIX) path of the file because we're about to run command line applications from this AppleScript.

--set this_item to quoted form of POSIX path of (choose file)

--------------------------------------------------------------------------------------

-- This section will make the script a folder action, meaning when images are added to the folder, they are processed by the script automatically

on adding folder items to this_folder after receiving these_items --<
	
	try --<
		repeat with i from 1 to number of items in these_items --<
			set this_item to item i of these_items --<
			
			--------------------------------------------------------------------------------------
			
			try
				-- This shell script uses the command-line application 'convert' to resize the image to 600 pixels wide. The default resolution for convert is 72x72 dpi, so this also sets the resolution to that value. 
				
				do shell script "/opt/local/bin/convert -resize 600 " & ¬
					this_item & " " & this_item
				----------------------------------------------------------------------------------
				
				-- It may seem extraneous to now use sips, a separate command-line application, to change the file colorspace to RGB, but convert seems to do weird things to the file when using the -colorspace argument, so we are using sips. sips  is automatically installed with each Mac OSX installation.
				
				do shell script "/usr/bin/sips -m '/System/Library/ColorSync/Profiles/Generic RGB Profile.icc'" & " " & this_item
				----------------------------------------------------------------------------------
				
			on error error_message
				display dialog error_message
			end try
			
		end repeat --<
	end try --<
end adding folder items to --<

--------------------------------------------------------------------------------------


Again, thanks to everyone for your help.

Don