locked
Get Base64 encoded string of a web image RRS feed

  • Question

  • I can convert an image to base64 encoding, using [convert]::ToBase64String, but that only works with Get-Content as far as I can see.

    I want to get the base64 encoded string of an webimage, for example this image: https://i.imgur.com/Ou5sQ2N.png

    If I do:

    $img = Invoke-WebRequest -Method GET -Uri https://i.imgur.com/Ou5sQ2N.png

    [Convert]::ToBase64String($img.Content)

    It looks like a base64 string, but something goes wrong there because it creates a second line and it can't be interpreted.

    I don't wan't to download the image first, I must execute this on like 50,000 images.

    Invoke-RestMethod gives me a lot of strange characters.

    Thanks in advance!


    Wednesday, December 11, 2019 10:02 AM

Answers

  • [byte[]]$b = (Invoke-WebRequest -Method GET -Uri https://i.imgur.com/Ou5sQ2N.png).Content
    $b64 = [Convert]::ToBase64String($b)
    


    \_(ツ)_/

    • Marked as answer by Erjen Rijnders Wednesday, December 11, 2019 10:24 AM
    Wednesday, December 11, 2019 10:19 AM

All replies

  • [byte[]]$b = (Invoke-WebRequest -Method GET -Uri https://i.imgur.com/Ou5sQ2N.png).Content
    $b64 = [Convert]::ToBase64String($b)
    


    \_(ツ)_/

    • Marked as answer by Erjen Rijnders Wednesday, December 11, 2019 10:24 AM
    Wednesday, December 11, 2019 10:19 AM
  • Cool! Thanks a lot for your fast response and it works perfect.
    Wednesday, December 11, 2019 10:24 AM