Using ImageMagick works with some tricks that are in contrast to what they say in the manual.
But you have, before, to extract the icc profile from image.
And -profile command need to be used two time CMYK->CMYK>RGB vene if the documentation say to don’t do this.
set theInput to POSIX path of (choose file with prompt "Choose CMYK file")
set theOutput to POSIX path of (choose file name default name "Untitled.tif")
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile_(theInput)
set imageRep to theImage's representations()'s objectAtIndex_(0)
set targetSpace to current application's NSColorSpace's sRGBColorSpace()
set newImage to imageRep's bitmapImageRepByConvertingToColorSpace_renderingIntent_(targetSpace, current application's NSColorRenderingIntentPerceptual)
set tiffData to newImage's TIFFRepresentation()
tiffData's writeToFile_atomically_(theOutput, true)
Or doing it with ASObjC Runner:
script convertImage
set {theInput, theOutput} to current application's NSApp's passedValue() as list
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile_(theInput)
set imageRep to theImage's representations()'s objectAtIndex_(0)
set targetSpace to current application's NSColorSpace's sRGBColorSpace()
set newImage to imageRep's bitmapImageRepByConvertingToColorSpace_renderingIntent_(targetSpace, current application's NSColorRenderingIntentPerceptual)
set tiffData to newImage's TIFFRepresentation()
set theResult to tiffData's writeToFile_atomically_(theOutput, true)
return theResult
end script
set theInput to POSIX path of (choose file with prompt "Choose CMYK file")
set theOutput to POSIX path of (choose file name default name "Untitled.tif")
tell application id "au.com.myriad-com.ASObjC-Runner" -- ASObjC Runner.app
-- success will return true
set theResult to run the script {convertImage} passing {theInput, theOutput} with response
end tell
Sorry – when I translated from Objective-C I left a line out. The relevant code should be:
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile_(theInput)
set imageRep to theImage's representations()'s objectAtIndex_(0)
set targetSpace to current application's NSColorSpace's sRGBColorSpace()
set newImage to imageRep's bitmapImageRepByConvertingToColorSpace_renderingIntent_(targetSpace, current application's NSColorRenderingIntentPerceptual)
set tiffData to newImage's TIFFRepresentation()
tiffData's writeToFile_atomically_(theOutput, true)
Sorry for resurrecting an old topic, but I am wondering what the JPEG equivalent to TIFFRepresentation might be? I tried JPEGRepresentation, jpegRepresentation, NSJPEGRepresentation, NSjpegRepresentation, and they all give me an error of “Unrecognized Selector”.
Bonus question, is there an ApplescriptObjC way of reading the chosen files current color space or should I just use Image Events for that?
use AppleScript version "2.4" -- 10.11 or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
set theInput to (choose file with prompt "Choose CMYK file")
set theOutput to (choose file name default name "Untitled.jpg")
set theImage to current application's NSImage's alloc()'s initWithContentsOfURL:theInput
set imageRep to theImage's representations()'s objectAtIndex:0
set targetSpace to current application's NSColorSpace's sRGBColorSpace()
set bitmapRep to imageRep's bitmapImageRepByConvertingToColorSpace:targetSpace renderingIntent:(current application's NSColorRenderingIntentPerceptual)
set theProps to current application's NSDictionary's dictionaryWithObjects:{1.0, true} forKeys:{current application's NSImageCompressionFactor, current application's NSImageProgressive}
set jpegData to bitmapRep's representationUsingType:(current application's NSJPEGFileType) |properties|:theProps
jpegData's writeToURL:theOutput atomically:true
Use the relevant part above to get bitmap image rep, and then: