Detecting CYMK jpeg images
Ken Ray
kray at sonsothunder.com
Fri Feb 6 14:42:07 EST 2009
> Does anyone have a method in Transcript to detect the colour space of a jpeg
> image?
If you're on Mac, yes... you can use SIPS at the command line. Here's the
handlers I created for this - feel free to use them (although I don't have a
Windows or Linux version).
You'd use it like this:
on mouseUp
answer file "Select a JPEG:"
if it <> "" then
put stsImageData(it) into tImageInfoA
if tImageInfoA["colorSpace"] is "cmyk" then
answer "Sorry, bad image. Try again."
else
-- whatever you want to do
end if
end if
end mouseUp
function stsImageData pPathToImage
local tReturnDataA
switch (the platform)
case "MacOS"
put stsFormatPath(pPathToImage,"MacOSX") into pPathToImage
put shell("sips -g all " & pPathToImage) into tResult
if stsSIPSCheck(tResult,tPBR_CheckResult) <> "OK" then
return tPBR_CheckResult
else
put word -1 of line 5 of tResult into tReturnDataA["format"]
put word -1 of line 8 of tResult into tReturnDataA["DPIHeight"]
put word -1 of line 7 of tResult into tReturnDataA["DPIWidth"]
put word -1 of line 3 of tResult into tReturnDataA["pixelHeight"]
put word -1 of line 2 of tResult into tReturnDataA["pixelWidth"]
put word -1 of line 12 of tResult into tReturnDataA["colorSpace"]
return tReturnDataA
end if
break
default
-- not supported yet
break
end switch
end stsImageData
function stsSIPSCheck pResult, at pCheckResult
if "Error" is in pResult then
put lineOffset(cr&"Error",pResult) into tLine
if tLine <> 0 then
put line (tLine+1) of pResult into tErrLine
put offset(":",tErrLine) into tChar
if tChar <> 0 then
delete char 1 to tChar of tErrLine
end if
put "STSError: " & trim(tErrLine) into pCheckResult
else
put "STSError: Cannot get image data." into pCheckResult
end if
return "error"
else
return "OK"
end if
end stsSIPSCheck
function stsFormatPath pPath,pPlatform
-- assumes a full "/"-delimited path
switch pPlatform
case "MacOSX"
case "Unix"
put "\" & space & quote & "'`<>!;()[]?#$^&*=" into tSpecialChars
repeat for each char tChar in tSpecialChars
replace tChar with ("\" & tChar) in pPath
end repeat
break
case "Win32"
set the itemDel to "/"
put item -1 of pPath into tFile
put "\/:*?" & quote & "<>|" into tSpecialChars
repeat for each char tChar in tSpecialChars
replace tChar with ("-") in tFile
end repeat
put tFile into item -1 of pPath
replace "/" with "\" in pPath
break
end switch
return pPath
end stsFormatPath
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list