#!/bin/powershell - # # anim2gif [-b BASENAME] file.anim... # # This is a simple script to convert my own animation sequence file # which basically is a list of IM command line options, with added # comments back into a GIF Animations. file.anim --> file_anim.gif # # The animation sequence file can be extracted from an existing GIF animation # using the "gif2anim" script. It can also be generated using some other # porgram, or by hand. It does not actually even need to generate a GIF # animation but could actually be any sequence of "convert" command line # options. However it is designed for generating GIF aniamtions. # # OPTIONS # -b framename basename for the individual frames # -g addsfx Add '$addsfx.gif' to end of basename, not '_anim.gif' # -d dflg 1 Leave a work file(temp__anim2gif_work.ps1). # 0 Remove a work file.( Default ) # # Not supported in the PowerShell version. # -c Input frames are coalesced, ignore any initial page size # # The options basically perform slight modifications to the input animation # sequence file, and assumes it is in the format generated by the "gif2anim" # script. They are provided for convenience only. # # It does not currently attempt to optimize the animation in any way, unless # that optimization was given in the animation sequence file given. # #### # # WARNING: Input arguments are NOT tested for correctness. # This script represents a security risk if used ONLINE. # I accept no responsiblity for misuse. Use at own risk. # # Anthony Thyssen 20 April 1996 # # # Hiroshi Kamifuji 2022-02-04 # Ported UNIX-like sh to PowerShell. # Changed the method of specifying run-time arguments. # # Param( [String]$in, [String]$b = "", [String]$g = "", [Int]$d = 0 ) if ( $in -eq "" ) { Write-Host "Usage : anim2gif [-b framename] [-g addsfx] in " Exit } $basename = "" if ( $b ) { $basename = $b } $addsfx = "_anim.gif" if ( $g ) { $addsfx = "$g.gif" } $method = 0 $im6 = (gcm montage).Definition 2> -null $im7 = (gcm magick).Definition 2> -null if ( $im7 ) { $method = 1 $magick = "magick" } elseif ( $im6 ) { $method =2 $magick = "" } else { echo "ImageMagick cannot be found and cannot be executed." Exit } $anim_output = (pwd).Path + "\temp__anim2gif_work.ps1" # echo "anim_output : $anim_output" # $enc_utf8_with_bom = new-object System.Text.UTF8Encoding $true $enc_utf8_without_bom = new-object System.Text.UTF8Encoding $false $file = New-Object System.IO.StreamWriter($anim_output, $false, $enc_utf8_without_bom ) $animdata = gc $in $frs = 0 foreach ($ln in $animdata) { $j = -1 $lnd = $ln.Split(" ") for ($i=0; $i -lt $lnd.Count; $i++) { if ( $lnd[$i] -eq "#" ) { $j = $i break } } if ( $j -ge 0 ) { if ( $j -eq 0 ) { if ( $d ) { Write-Host $ln } $file.WriteLine( $ln ) $lnd, $wk1, $wk = $ln.Split("`"") if ( $wk1 ) { $basename = $wk1 } } else { $wk, $wk3 = $ln.Split("#") $wk1, $wk2 = $wk.Split("BASENAME") $wk = " $wk1 $basename$wk2 ``" if ( $d ) { Write-Host $wk } $file.WriteLine( $wk ) $frs++ } } else { if ( $frs -eq 0 ) { switch ( $method ) { # Execute by ImageMagick7.x 1 { $pr = " magick convert " + $ln + " ``" } # Execute by ImageMagick6.x 2 { $pr = " convert " + $ln + " ``" } } } else { $pr = " " + $ln + " ``" } if ( $d ) { Write-Host $pr } $file.WriteLine( $pr ) $frs++ } } $out = "$basename$addsfx" if ( $d ) { Write-Host " $out" } $file.WriteLine( " $out" ) $file.Close() ./temp__anim2gif_work.ps1 if ( ! $d ) { rm ./temp__anim2gif_work.ps1 }