• 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: ps to tiff question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ps to tiff question


  • Subject: Re: ps to tiff question
  • From: Shane Stanley <email@hidden>
  • Date: Thu, 06 Oct 2016 10:04:42 +1100

On 6 Oct. 2016, at 6:26 am, Mark Workman <email@hidden> wrote:

I have been looking for a way to convert postscript files to tiff files in Applescript. I haven’t found a way to do this directly. The best way found so far seems to be use pstopdf then use ImageEvents to convert the pdf to tiff.
Is there a better way to do this?

If you're using 10.10 or later, this might suit your needs:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set posixPath to "/Users/shane/Desktop/Sample EPS.ps"
set thisResult to its makeTiffFromEPSAt:posixPath withDPI:300

on makeTiffFromEPSAt:posixPath withDPI:dpi
set posixPath to current application's NSString's stringWithString:posixPath
set destPath to posixPath's stringByDeletingPathExtension()'s stringByAppendingPathExtension:"tif"
# make image representation from file
set oldRep to current application's NSEPSImageRep's imageRepWithContentsOfFile:posixPath
set imageSize to oldRep's |size|()
set theWidth to width of imageSize
set newWidth to theWidth * dpi / 72
set theHeight to height of imageSize
set newHeight to theHeight * dpi / 72
-- make new bitmap the right size
set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:newWidth pixelsHigh:newHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSDeviceRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
-- store the existing graphics context
current application's NSGraphicsContext's saveGraphicsState()
-- set graphics context to new context based on the new bitmapImageRep
current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep)
-- draw from old rep into bitmap 
oldRep's drawInRect:{origin:{x:0, y:0}, |size|:{width:newWidth, height:newHeight}} fromRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:theHeight}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
-- restore graphics state
current application's NSGraphicsContext's restoreGraphicsState()
# extract tiff data
set theData to newRep's representationUsingType:(current application's NSGIFFileType) |properties|:{NSImageCompressionMethod:(current application's NSTIFFCompressionLZW)}
# save to file
theData's writeToFile:destPath atomically:true
end makeTiffFromEPSAt:withDPI:

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


 _______________________________________________
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: 
 >ps to tiff question (From: Mark Workman <email@hidden>)

  • Prev by Date: Re: stringWithContentsOfURL works when it's a script, not when it's an app
  • Next by Date: Re: stringWithContentsOfURL works when it's a script, not when it's an app
  • Previous by thread: RE: ps to tiff question
  • Next by thread: Accessibility
  • Index(es):
    • Date
    • Thread