from JascApp import *

# if you want thumbnails generated at a different size just change this to the desired value.
MaxThumbnailSize = 150

def ScriptProperties():
    return {
        'Author': u'Jasc Software, Inc.',
        'Copyright': u'Copyright (c) 2002-2004 Jasc Software, Inc.  All rights reserved.',
        'Description': "Make a thumbnail of the current file at a size of no larger than 150x150, preserving the aspect ratio.",
        'Host': u'Paint Shop Pro',
        'Host Version': u'8.00'
        }

# Begin Translatable Strings
DocumentSizeMsg = "Document %s smaller than requested thumbnail - no change made"
ResizedMsg = "Document %s resized to %d x %d"
# End Translatable Strings

def Do(Environment):
    # compute the width and the height of image, preserving the aspect ratio
    ImageInfo = App.Do( Environment, 'ReturnImageInfo' )
    Width = ImageInfo['Width']
    Height = ImageInfo['Height']
    Title = ImageInfo['Title']
    
    if Width <= MaxThumbnailSize and Height <= MaxThumbnailSize:
        print DocumentSizeMsg % ( Title )
        return
    elif Width > Height:
        NewWidth  = MaxThumbnailSize
        NewHeight = Height * float(NewWidth) / float(Width)
    else:   # height > width
        NewHeight = MaxThumbnailSize
        NewWidth  = Width * float(NewHeight) / float(Height)

    print ResizedMsg  % ( Title, NewWidth, NewHeight )
    
    App.Do( Environment, 'Resize', {
            'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 
            'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 
            'MaintainAspectRatio': App.Constants.Boolean.true, 
            'OriginalDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 
            'OriginalResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 
            'Resample': App.Constants.Boolean.true, 
            'ResampleType': App.Constants.ResampleType.SmartSize, 
            'ResizeAllLayers': App.Constants.Boolean.true, 
            'Resolution': 100.000, 
            'Width': NewWidth, 
            'Height': NewHeight, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

