• 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
Re: Color Conversion Gone Bad in Mavericks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Color Conversion Gone Bad in Mavericks


  • Subject: Re: Color Conversion Gone Bad in Mavericks
  • From: Shane Stanley <email@hidden>
  • Date: Fri, 21 Feb 2014 10:12:58 +1100

On 20 Feb 2014, at 5:30 pm, Håvard Graudo <email@hidden> wrote:

My workaround was to do only one command in each line:

If you have a solid-state drive, the extra IO time is probably neither here nor there, but it is inefficient. FYI, you can do this too using an ASObjC-based lib:

use framework "Foundation"
use framework "AppKit"

on pngFromPath:imagePath toPath:newPath maxDimension:maxDim
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath -- load the file as an NSImage
-- calculate required sizes
set theSize to (theImage's |size|()) as record
set oldWidth to width of theSize
set oldHeight to height of theSize
if oldWidth > oldHeight then
set theWidth to maxDim
set theHeight to oldHeight / oldWidth * maxDim
else
set theHeight to maxDim
set theWidth to oldWidth / oldHeight * maxDim
end if
set newImage to current application's NSImage's alloc()'s initWithSize:(current application's NSMakeSize(theWidth, theHeight)) -- make new blank image
-- draw from original to new
newImage's lockFocus()
theImage's drawInRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:theHeight}} fromRect:(current application's NSZeroRect) operation:(current application's NSCompositeSourceOver) fraction:1.0
newImage's unlockFocus()
set theData to newImage's TIFFRepresentation() -- get bitmap as data
set newRep to current application's NSBitmapImageRep's imageRepWithData:theData -- make bitmap from data
set theData to (newRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageGamma:1.0}) -- turn the bitmap into PNG data
(theData's writeToFile:newPath atomically:true) -- write it to disk
end pngFromPath:toPath:maxDimension:

Call it with:

use theLib : script "<name of lib>" 

theLib's pngFromPath:"/Users/shane/Desktop/Test.pdf" toPath:"/Users/shane/Desktop/Test.png" maxDimension:2000


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Color Conversion Gone Bad in Mavericks (From: Jon Rosen <email@hidden>)
 >Re: Color Conversion Gone Bad in Mavericks (From: Håvard Graudo <email@hidden>)

  • Prev by Date: Re: Color Conversion Gone Bad in Mavericks
  • Next by Date: Re: Color Conversion Gone Bad in Mavericks
  • Previous by thread: Re: Color Conversion Gone Bad in Mavericks
  • Next by thread: Re: Color Conversion Gone Bad in Mavericks
  • Index(es):
    • Date
    • Thread