diff --git a/scripts/piped-work/decorate_images.py b/scripts/piped-work/decorate_images.py new file mode 100644 index 000000000..69e649719 --- /dev/null +++ b/scripts/piped-work/decorate_images.py @@ -0,0 +1,83 @@ +# decorate_images.py +# Crops and drop-shadows images for the manual + +from PIL import Image +from PIL import ImageFilter +import glob +import os + +# Edit these to your image source and image destination paths. +src = "C:/OpenSourceGit/AudacityTeamTools/wit-html/trim_me" +dest = "C:/OpenSourceGit/AudacityTeamTools/wit-html/processed" + +# from https://en.wikibooks.org/wiki/Python_Imaging_Library/Drop_Shadows +def makeShadow(image, iterations, border, offset, backgroundColour, shadowColour): + # image: base image to give a drop shadow + # iterations: number of times to apply the blur filter to the shadow + # border: border to give the image to leave space for the shadow + # offset: offset of the shadow as [x,y] + # backgroundCOlour: colour of the background + # shadowColour: colour of the drop shadow + + #Calculate the size of the shadow's image + fullWidth = image.size[0] + abs(offset[0]) + 2*border + fullHeight = image.size[1] + abs(offset[1]) + 2*border + + #Create the shadow's image. Match the parent image's mode. + shadow = Image.new(image.mode, (fullWidth, fullHeight), backgroundColour) + + # Place the shadow, with the required offset + shadowLeft = border + max(offset[0], 0) #if <0, push the rest of the image right + shadowTop = border + max(offset[1], 0) #if <0, push the rest of the image down + #Paste in the constant colour + shadow.paste(shadowColour, + [shadowLeft, shadowTop, + shadowLeft + image.size[0], + shadowTop + image.size[1] ]) + + # Apply the BLUR filter repeatedly + for i in range(iterations): + shadow = shadow.filter(ImageFilter.BLUR) + + # Paste the original image on top of the shadow + imgLeft = border - min(offset[0], 0) #if the shadow offset was <0, push right + imgTop = border - min(offset[1], 0) #if the shadow offset was <0, push down + shadow.paste(image, (imgLeft, imgTop)) + + return shadow + +# crops on 3 sides. +def crop3_one( image, d ) : + w,h = image.size + image = image.crop( (d, 0, w-d, h-d) ) + return image + +#crops on 4 sides +def crop4_one( image, d ) : + w,h = image.size + image = image.crop( (d, d, w-d, h-d) ) + return image + +# Take this one full path name, process it, output to dest directory. +def process_one( name ): + global dest + name = os.path.realpath( name ) + image = Image.open( name ) + + #---- Start of image processing steps + image = crop4_one( image, 4 ) + image = makeShadow( image, 3, 2, [2,2], (255,255,255), (80,80,80) ) + #---- End of image processing steps + + path, fname = os.path.split( name ) + print( "Name:", fname, " Size:", image.size ) + image.save( "/".join( (dest, fname )) ) + + +# Process all .png images in directory +for filename in glob.iglob(src + '/*.png'): + name = os.path.realpath( filename ); + process_one(name) + + +#process_one( 'C:/OpenSourceGit/AudacityTeamTools/wit-html/trim_3/AfterChirp.png' ) diff --git a/scripts/piped-work/docimages_regression_tests.py b/scripts/piped-work/docimages_regression_tests.py new file mode 100644 index 000000000..483a7c4b0 --- /dev/null +++ b/scripts/piped-work/docimages_regression_tests.py @@ -0,0 +1,30 @@ +# docimages_regression_tests.py +# Sends commands to get images for the manual. +# Tests against bug numbers to confirm that they are still fixed. + +# Make sure Audacity is running first and that mod-script-pipe is enabled +# before running this script. + +#load and run the common core. +exec( open("docimages_core.py" ).read() ) + + +def bug_test_1844(): + makeWayForTracks() + do( 'Select: Start=0 End=30' ) + do( 'Silence' ) + do( 'Select: Start=0 End=40' ) + do( 'ZoomSel' ) + do( 'Select: Start=0 End=30' ) + do( 'Tone' ) + do( 'EnvelopeTool' ) + do( 'SetEnvelope: Time=10 Value=1.0' ) + do( 'SetEnvelope: Time=12 Value=0.5' ) + do( 'Select: Start=0 End=4' ) + do( 'AdjustableFade: curve="0" gain0="0" gain1="100" preset="None Selected" type="Fade Up" units="% of Original" ' ) + capture( "Bug1844.png", "All_Tracks" ) + do( 'SelectTool' ) + +# Should have envelop points at 0s, 2x4s, 10s and 12s and no others. +bug_test_1844() +