Auteur Sujet: L'art et intelligence artificielle ou le grand détournement  (Lu 5010 fois)

0 Membres et 1 Invité sur ce sujet

Hors ligne Arenas

  • Newbie
  • *
  • Messages: 17
  • Karma : 2
    • Voir le profil
    • http://arenas.pagesperso-orange.fr/GradientExample/france-countdown.html
L'art et intelligence artificielle ou le grand détournement
« le: avril 30, 2023, 23:45:15 pm »
L'Art numérique

Le scripte ( fonction )

For PowerShell  version  4 or plus
===============
cls

function Convert-ImageToAsciiArt
{
  param(
    [Parameter(Mandatory)][String]
    $Path,
   
    [ValidateRange(20,20000)]
    [int]$MaxWidth=80,
   
    # character height:width ratio
    [float]$ratio = 2 # 1.5
  )

  # load drawing functionality
  Add-Type -AssemblyName System.Drawing
 
  # characters from dark to light
  $characters = '$#H&@*+;:-,. '.ToCharArray()
  $c = $characters.count
 
  # load image and get image size
  $image = [Drawing.Image]::FromFile($path)
  [int]$maxheight = $image.Height / ($image.Width / $maxwidth)/ $ratio
 
  # paint image on a bitmap with the desired size
  $bitmap = new-object Drawing.Bitmap($image,$maxwidth,$maxheight)
 
 
  # use a string builder to store the characters
  [System.Text.StringBuilder]$sb = ""
 
  # take each pixel line...
  for ([int]$y=0; $y -lt $bitmap.Height; $y++){
    # take each pixel column...
    for ([int]$x=0; $x -lt $bitmap.Width; $x++){
      # examine pixel
      $color = $bitmap.GetPixel($x,$y)
      $brightness = $color.GetBrightness()
      # choose the character that best matches the
      # pixel brightness
      [int]$offset = [Math]::Floor($brightness*$c)
      $ch = $characters[$offset]
      if (-not $ch){ $ch = $characters[-1] }     
      # add character to line
      $null = $sb.Append($ch)
    }
    # add a new line
    $null = $sb.AppendLine()
  }

  # clean up and return string
  $image.Dispose()
  $sb.ToString()
}

$Path = "C:\......."
$OutPath = "C:\........txt"

Convert-ImageToAsciiArt -Path $Path -MaxWidth 100 |
Set-Content -Path $OutPath -Encoding UTF8

Invoke-Item -Path $OutPath

====================
30.04.2023 23h45
Origine file (your format)


Sortie d'image en format txt
« Modifié: juillet 17, 2023, 09:45:40 am par Arenas »