Hello,
Here's the modified script that should do the job.
if (-not $Context.IsPropertyModified("thumbnailPhoto"))
{
return; # the thumbnailPhoto property is not modified
}
# Get the thumbnailPhoto
$thumbnailPhotoBytes = $Context.GetModifiedPropertyValue("thumbnailPhoto");
if ($thumbnailPhotoBytes -eq $NULL)
{
return; # the thumbnailPhoto property is being deleted
}
# Write the photo to temporary file
$tmpFilePath = [System.IO.Path]::GetTempFileName();
[System.IO.File]::WriteAllBytes($tmpFilePath, $thumbnailPhotoBytes);
# TODO: Launch an external command to resize the photo ($tmpFilePath)
& "C:\Adaxes\Scripts\Convert\Convert.exe" "$tmpFilePath" -quality 96 -depth 8 -strip -thumbnail 96x96^ -gravity Center -crop 96x96+0+0 "$tmpFilePath"
# Read the modified file
$thumbnailPhotoBytes = [System.IO.File]::ReadAllBytes($tmpFilePath);
# Delete the temporary file
[System.IO.File]::Delete($tmpFilePath);
# Replace the photo with the modified one
$Context.SetModifiedPropertyValue("thumbnailPhoto", $thumbnailPhotoBytes);
The thing is that whenever you launch an executable file in PowerShell, it should be preseed with an & symbol. Otherwise PowerShell will treat the line as a PowerShell command.
Also, you saved the converted file to $tmpFilePath\Converted.jpg, but tried to upload to directory not the converted file, but the original source file before conversion.