• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSImage Resize
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage Resize


  • Subject: NSImage Resize
  • From: James Yanchak <email@hidden>
  • Date: Mon, 14 Sep 2015 13:16:39 -0400

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  
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSImage Resize
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: How to specify cocoa bindings options?
  • Next by Date: Re: NSImage Resize
  • Previous by thread: Re: How to specify cocoa bindings options?
  • Next by thread: Re: NSImage Resize
  • Index(es):
    • Date
    • Thread