Hi all, new to list and hoping someone could explain where I am going wrong. I am trying to read in a TIF file, modify its size, then export back out as a JPEG.
Everything works: reading the file, changing the file (it actually gets new dimensions), but the output file never comes out at those dimensions. This is what I have so far:
use scripting additions use framework "Foundation" use framework “AppKit"
set thePicture to "/Users/jamesyanchak/Desktop/9780203007198.tif" set thisResult to its aocConvertImageFileAtPath:{thePicture, "jpg", 1600}
on aocConvertImageFileAtPath:{locImageFilePath, exportFileFormat, imageWidthPixels} set locImageOriginal to current application's NSString's stringWithString:locImageFilePath set locImageNew to locImageOriginal's stringByDeletingPathExtension()'s stringByAppendingPathExtension:exportFileFormat # make NSImage from file set thisImage to current application's NSImage's alloc()'s initWithContentsOfFile:locImageOriginal # set the image to its new size set imageMeasures to (thisImage's |size|()) set scalePercentage to (imageWidthPixels / (imageMeasures's width)) set newWidth to (imageMeasures's width) * scalePercentage set newHeight to imageMeasures's height #<— this in just to give a visual aid to show it changed in the output file thisImage's setSize:{width:newWidth, height:newHeight} # get TIFF version as data set thisImageDataAsTIFF to thisImage's TIFFRepresentation() # make bitmap representation from TIFF data set thisImageDataAsBITMAP to current application's NSBitmapImageRep's imageRepWithData:thisImageDataAsTIFF # extract jpeg set theData to thisImageDataAsBITMAP's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.5} # save to file theData's writeToFile:locImageNew atomically:true end aocConvertImageFileAtPath:
Thanks in advance.
James |