taers232c / GAMADV-XTD3

Command line tool to manage Google Workspace
691 stars 86 forks source link

Profile photo image format #351

Closed DanielMalmgren closed 1 year ago

DanielMalmgren commented 1 year ago

Hi. In #322 I mentioned the problem that profile photos returned by Google and thus also by "gam user get profilephoto" always have the suffix .jpg although they aren't always that. If the user uploaded a png as their profile photo you get a png file with wrong suffix. This became a problem for me, so I wrote a little function for correcting the name. I'm just wondering if something like this could be incorporated into GAM to get the correct file name from the beginning?

My function looks like this:

function Get-CorrectFileSuffix {

    param ([string]$filePath)

    $jpegSignature = [byte[]](0xFF, 0xD8, 0xFF, 0xE0)
    $pngSignature = [byte[]](0x89, 0x50, 0x4E, 0x47)

    $bytes = [byte[]](Get-Content $filePath -Encoding Byte -TotalCount 4)

    if (!(Compare-Object $bytes $jpegSignature)) {
        ".jpg"
    } elseif (!(Compare-Object $bytes $pngSignature)) {
        ".png"
    } else {
        Write-Error "Neither jpeg och png!"
    }

}
taers232c commented 1 year ago

Daniel,

I'll add this; thanks for your owrk.

Ross

Ross Scroggs @.***

On Apr 12, 2023, at 12:31 AM, Daniel Malmgren @.***> wrote:

Hi. In #322 https://github.com/taers232c/GAMADV-XTD3/issues/322 I mentioned the problem that profile photos returned by Google and thus also by "gam user get profilephoto" always have the suffix .jpg although they aren't always that. If the user uploaded a png as their profile photo you get a png file with wrong suffix. This became a problem for me, so I wrote a little function for correcting the name. I'm just wondering if something like this could be incorporated into GAM to get the correct file name from the beginning?

My function looks like this:

function Get-CorrectFileSuffix {

param ([string]$filePath)

$jpegSignature = [byte[]](0xFF, 0xD8, 0xFF, 0xE0)
$pngSignature = [byte[]](0x89, 0x50, 0x4E, 0x47)

$bytes = [byte[]](Get-Content $filePath -Encoding Byte -TotalCount 4)

if (!(Compare-Object $bytes $jpegSignature)) {
    ".jpg"
} elseif (!(Compare-Object $bytes $pngSignature)) {
    ".png"
} else {
    Write-Error "Neither jpeg och png!"
}

} — Reply to this email directly, view it on GitHub https://github.com/taers232c/GAMADV-XTD3/issues/351, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCTYL63R3OEPKD3PK7JTTLXAZK6NANCNFSM6AAAAAAW3JA2PM. You are receiving this because you are subscribed to this thread.

taers232c commented 1 year ago

Done in 6.52.04

Ross Scroggs @.***

On Apr 12, 2023, at 12:31 AM, Daniel Malmgren @.***> wrote:

Hi. In #322 https://github.com/taers232c/GAMADV-XTD3/issues/322 I mentioned the problem that profile photos returned by Google and thus also by "gam user get profilephoto" always have the suffix .jpg although they aren't always that. If the user uploaded a png as their profile photo you get a png file with wrong suffix. This became a problem for me, so I wrote a little function for correcting the name. I'm just wondering if something like this could be incorporated into GAM to get the correct file name from the beginning?

My function looks like this:

function Get-CorrectFileSuffix {

param ([string]$filePath)

$jpegSignature = [byte[]](0xFF, 0xD8, 0xFF, 0xE0)
$pngSignature = [byte[]](0x89, 0x50, 0x4E, 0x47)

$bytes = [byte[]](Get-Content $filePath -Encoding Byte -TotalCount 4)

if (!(Compare-Object $bytes $jpegSignature)) {
    ".jpg"
} elseif (!(Compare-Object $bytes $pngSignature)) {
    ".png"
} else {
    Write-Error "Neither jpeg och png!"
}

} — Reply to this email directly, view it on GitHub https://github.com/taers232c/GAMADV-XTD3/issues/351, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCTYL63R3OEPKD3PK7JTTLXAZK6NANCNFSM6AAAAAAW3JA2PM. You are receiving this because you are subscribed to this thread.

DanielMalmgren commented 1 year ago

Thanks a lot! Just for the correctness though, I think it should be 6.54.02, not the other way around.