Editing image and saving to disk
Editing image and saving to disk
- Subject: Editing image and saving to disk
- From: "Adrian R. Foltyn" <email@hidden>
- Date: Mon, 12 Jul 2004 20:32:18 +0200
Hi there,
I'm trying to change some properties of a loaded image and then saving
it back to disk. I'm trying to do this because "Image Events"
apparently can't deal with TIFF files that have transparency when
converting to JPEG making the transparent areas a mess of colors.
There seems to be no problem to run the image through some "call
methods" and then later on saving the data back to disk. My problem is
that any changes I do to the image are somehow not registered. I tried
to call methods like "update", "register" and "draw" but the problem
remained.
Would be great if somebody could give me a hint on what's wrong. The
script is included below.
Thanks,
Adrian
-----------------------------------------------------
-- Specifying the input and output paths
set pathToImage to "Macintosh HD:Users:foo:Desktop:transparent.tiff"
set savePath to "Macintosh HD:Users:foo:Desktop:converted.tiff"
-- This can be done with any ASS application
tell application "AppleScriptStudioApplicationName"
-- The TIFF file at pathToImage is loaded and stored in myNSImage
set myNSImage to load image POSIX path of pathToImage
-- Getting the first (default?) NSBitmapImageRep of the NSImage
set myNSBitmapImageRep to item 1 of (call method "representations" of
myNSImage)
-- For testing purposes only the size and alpha of the representation
are changed
call method "setSize:" of myNSBitmapImageRep with parameter {10, 10}
call method "setAlpha:" of myNSBitmapImageRep with parameter "NO"
-- To later on reflect on the changes made, the description of the
representation is saved
set descriptionBefore to call method "description" of
myNSBitmapImageRep
-- To save the representation to disk later on we have to get the TIFF
data first
set tiffData to call method "TIFFRepresentation" of myNSBitmapImageRep
-- Another save of the description of the representation
set descriptionAfter to call method "description" of myNSBitmapImageRep
end tell
-- Writing the TIFF data to file, atomically
do shell script "rm -f " & quoted form of (POSIX path of savePath)
open for access file savePath with write permission
write tiffData to file savePath
close access file savePath
-- Opening the "converted" image in Preview
tell application "Preview" to open file savePath
-- Returning the descriptions to see that the changes to the
-- representation were lost after getting the TIFFRepresentation
return descriptionBefore & return & descriptionAfter
(*
Returns:
NSBitmapImageRep 0x3e0a40 Size={10, 10}
ColorSpace=NSCalibratedRGBColorSpace BPS=8 Pixels=32x32 Alpha=NO
NSBitmapImageRep 0x3e0a40 Size={32, 32}
ColorSpace=NSCalibratedRGBColorSpace BPS=8 Pixels=32x32 Alpha=YES
*)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.