PngMagic - a simple JavaScript based image maker and batch image processor.

Version 0.15: Added Pm.Window.  Used in Clock.js as a clock / CPU widget. Can be dragged from top edge.
Version 0.14: Added CenterX, CenterY to PathBrush
Version 0.13: Added CenterX, CenterY to PathBrush
Version 0.12: Fixed Pen caps
Version 0.11: Added Gdi.DrawPatch. Used in Copy9patch.js.
Version 0.10: Testing completed. Done for now.

  For 9-patch information see Reference
  For fixing locked png transparency pallets use the FixPng script.

Download   If you like it, please consider donating on the home page

Drag and drop scripts over the window to load them, or click from the list.  Any changes are automatically saved. Drag images to insert full path at current position.

Click Run to run them.

Save As... to save new scripts.

New (in context menu) to save current script and clear text editor (Unsaved will be in Untitled.js)
 
Combo Inserts:  Select one, then right click and select "Insert Template" in the context menu to insert it at the current cursor position.
<Color>              Inserts a Gdi.Argb(...) after color is chosen. Clicking on the image before inserting can set the starting palette color.
<Filename>         Inserts a 'Full path\\filename' or folder after chosen.
 <Font>               Inserts a Gdi.Font( name, size, properties) after selecting OK on a font chooser.
<x, y, w, h>        Inserts last clicked position in image display.  Click for just x, y, or press hold drag release for x,y,w,h.
< x1, y1, x2, y2>  Same as above but inserts absolute position for x2, y2.

The rest are templates.
General Helper Functions Red = optional
value = Pm.Argb(Alpha, Red, Green, Blue)
Example: Pm.Clear( Gdi.Argb(255, 0, 0, 0) )
Pm.Beep( var )
Example: Pm.Beep( 0 )                                         // Default Windows beep
name = Pm.BrowseFile( 'defaultFile', 'Title' )            // Request a filename from user and return it in a variant
name = Pm.BrowseFolder( 'defaultFolder', 'Tiitle')    // Request a folder and return it
Pm.Color( 'Item' ) = Rgb                                         // Set colors of different editor components
Rgb = Pm.Color( 'item' )                                         // Items: Background, Text, Comment, Number, String, Function, Constant
Pm.Echo( var )                                                      // Displays text in output window
Example: Pm.Echo( 'var i is ' + i )                           // Display the value of i
Pm.Run( Script )                                                   // Rerun the current script when done, or optionally run another script  in the Scripts folder (use just name, no .js)
Pm.Name( )                                                          // Call a script from the Scripts folder
Pm.PlaySound( File )                                           // Play a wav file. Same folder as exe or give full path
Example: Pm.PlaySound( 'C:\\Windows\\Media\\Tada.wav' )
Pm.FileExists( 'Filename' )
Example: If( Pm.FileExists( 'C:\\Windows\\win.ini' ) ) Pm.PlaySound( 'Ding.wav' )
Pm.Quit( )
Example: Pm.Quit()                                             // Stop script
value = Pm.Width                                               // width and height of drawing area
value = Pm.Height
Pm.Width = width                                               // set new width (display area will scale)
Pm.Height = height
Pm.Smoothing = 'Option'                                    // None or Low, High or AntiAlias, 8x8
smoothing = Pm.Smoothing
Pm.Window( 'Name' )                                        // Creates new window.  All drawing for script will continue there instead of default window.
Drawing objects    Red = optional
Gdi.Pen( ARGB, Width, DashStyle|DashArray, DashOffset, DashCap// Styles: Solid, Dash, Dot, DashDot, DashDotDot - Caps: Flat, Round, Triangle, Square, Arrow, SArrow, EArrow
Example: Gdi.Pen( 0xFF00FF00, 1.0)                              // Green, smallest size
             
 dashes = new Array(20, 10)                             // Long lines with half spaces
              
Gdi.Pen( Gdi.Argb(255, 255, 0, 0), dashes)       // Red lines using the dash array
Gdi.Brush( ARGB )
Example:
Gdi.GradientBrush( X1, Y1, X2, Y2, StartARGB, EndARGB, Angle ) //
Example:
Gdi.PathBrush( PointArray, CenterColor, ColorArray, CenterX, CenterY )            //
Example:
Gdi.TextureBrush( Filename, TileSize )                                // Note: Current pen will inherit gradient
Example:
Drawing Functions Red = optional
Gdi.Clear( ARGB )
Example: Gdi.Clear(0x00000000)                                        // Set background to black, transparent
Example: Gdi.Clear(0xFF000000)                                       // Set background to black, opaque
Gdi.Line( StartX, StartY, EndX, EndY )                               // Uses last pen, draw a line from start to end
Example:
Gdi.Arc( X, Y, Width, Height, StartAngle, SweepAngle )       // Uses last pen
Example:
Gdi.Bezier( X1, Y1, X2, Y2, X3, Y3, X4, Y4 )                        // Uses last pen
Example:
Gdi.Rectangle( X, Y, Width, Height )                                   // Uses last pen
Gdi.FillRectangle( X, Y, Width, Height )                              
// Uses last brush
Example:
Gdi.Ellipse( X, Y, Width, Height )                                       // Uses last pen
Gdi.FillEllipse( X, Y, Width, Height )                                  
// Uses last brush
Example:
Gdi.Pie( X, Y, Width, Height, StartAngle, SweepAngle )       // Uses last pen
Gdi.FillPie( X, Y, Width, Height, StartAngle, SweepAngle )  
// Uses last brush
Example:
Gdi.Polygon( PointArray, CornerRadius )                            // Use pen to draw polygon  (array[0] = x1, array[1] = y1, array[2] = x2, array[3] = y2.....)
Gdi.FillPolygon( PointArray, CornerRadius )                        // Use brush to draw filled polygon using array object, optionally with rounded corners
Gdi.Curve( PointArray, tension)                                          // Use pen to draw a curve
Gdi.ClosedCurve( PointArray, tension)                                // Use pen to draw a closed curve
Gdi.FillClosedCurve( PointArray, tension)                            // Use brush to draw a filled closed curve
Argb = Gdi.Pixel( X, Y)                                                      // Get value of pixel at XY
Gdi.Pixel(X, Y) = Argb                                                       // Set pixel at XY
Gdi.Font( 'Fontname', Size, 'Style' )                                   // Set font for text  Style: Regular, Bold, Italic, BoldItalic, Underline, Strikeout
Example: Gdi.Font( 'Digital dream', 12)                               // Set font to Digital dream, size 12, normal style
Gdi.Text( String, X, Y, Alignment, Angle|Points )                 // Draw text using current font and last brush. Alignment = 'Left' 'Center' 'Right'
Example:
Gdi.OutlineText( String, X, Y, Fill, Alignment, Angle|Points ) // Draw outlined text using current font using last pen (and last brush if Fill = true)
Example:
   Gdi.Brush( Gdi.Argb(255, 255, 20, 255) ) // Purple brush
   Gdi.Pen( Gdi.Argb(20, 0, 0, 255), 1)        // Blue pen 20 alpha, 1px
   Gdi.OutlineText( 'Hello', 10, 10, 8)           // Draw purple Hello with soft blue glow (Fill > 1) = pen stroke radius
Image Functions
FrameCount = Gdi.LoadImage( Filename, 'Decompile' | Frame )  // Load an image (jpg, png, bmp, gif, ...) Decompile decompiles a 9-patch png
Example:
Gdi.Copy( X, Y, Width, Height, 'Option')  // Copy a section as an Image. Option: FlipX, FlipY, FlipXY, Rotate90FlipX (90,180,270) (X,Y,XY)
Example:
Gdi.RotateImage( X, Y, Angle, Size ) // Draw the image, at XY, rotated at Angle, stretched to Size maintaining aspect
Example:
Gdi.DrawImage( X, Y, Width, Height ) // Draw the image (Width only = specify size w/correct aspect | Width + Height = stretch)
Example:
value = Gdi.ImageWidth                   // get current image width/height
value = Gdi.ImageHeight

Example: Gdi.Echo( 'Image size is ' + Gdi.ImageWidth + ' by ' + Gdi.ImageHeight )
bool = Gdi.IsCompiled                     // True if last loaded image is a compiled 9-patch (Will be false If .9 and not compiled, but 9-patch will be generated)
Gdi.Save( Filename, X, Y, Width, Height, 'Option') // Supports png, jpg, tiff, bmp (Option: 'Compile' a 9-patch png or 'Clone' last loaded 9-patch)
Example: Gdi.Save( 'TestImage.png')                   // Save the current image to the current directory uncropped
Gdi.SetPatch( xStart, xEnd, yStart, yEnd, PaddingTop, PaddingBottom, PaddingLeft, PaddingRight) // When saving, use 'Clone' option
This sets 9-patch data programmatically instead of drawn, but can only do 1 pair per X/Y.
Gdi.Download( 'http://url', [filename]) // Reads a file off internet.  Returns path/filename saved
Example:  name = Gdi.Download( 'http://www.google.com', 'google.html' )
Effects Uses full work area if no dimensions set
Gdi.Blur( Radius, ExpandEdge , Left, Top, Right, Bottom)                                     // Radius in pixels (0-255), ExpandEdge = true/false
Gdi.BrightnessContrast( Brightnes, Contrast, Left, Top, Right, Bottom)                   // Brightness +/-255, Contrast +/-100
Gdi.ColorBalance( CyanRed, MagentaGreen, YellowBlue, Left, Top, Right, Bottom) // Color Range +/-100, 0 = Unchanged
Gdi.HueSaturationLightness( Hue, Saturation, Lightness, Left, Top, Right, Bottom) // Hue +/-180, Saturation +/-100, Lightness +/-100
Gdi.Levels( Highlight, Midtone, Shadow, Left, Top, Right, Bottom)                         // Highlight 0-100 (100=Unchanged), Midtone +/-100 (0=Unchanged), Shadow 0-100 (0=Unchanged)
Gdi.Sharpen( Radius, Amount, Left, Top, Right, Bottom)                                      // Radius in pixels (0-255), Amount 0-100
Gdi.Tint( Hue, Amount, Left, Top, Right, Bottom)                                                 // Hue +/-180, Amount +/-100

Notes:

  The entire JavaScript language is available excluding any html based extensions.

  All variants are persistent.  As long as the program is running, all variants will remain the same the next time a script is run.  So when running different scripts in sequence, the pen, brush, image, variables, strings, arrays, and work area will be the same as where the last script left off.

 Init.js is always run at start.  Use this to predefine any constants.

 

Copyright © 2013 Curious Technology