ConvertTo-Jpeg
ConvertTo-Jpeg copied to clipboard
Touch the new file to reflect the time and date of the source file
When sorting images by date, important when mixing images from different sources, the converted files have the date of the conversion and not the date of the original file. Please change the Date Created and Date Modified to match the original file.
Proposed Modification:
Process { # store input file's dates and set them on the detination file $fileCreateDate = $null; $fileModifiedDate = $null; $outFileName = ""
# Summary of imaging APIs: https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/imaging
foreach ($file in $Files)
{
**$outFileName = ""**
# Get SoftwareBitmap from input file
$file = Resolve-Path -LiteralPath $file
**$fileCreateDate = (Get-Item $file).CreationTime # Malcolm Stewart
$fileModifiedDate = (Get-Item $file).LastWriteTime # Malcolm Stewart**
**# $outputFileName = $inputFile.Name + ".jpg";
$outputFileName = $inputFile.Name -replace $inputFile.FileType, ".jpg"; # Malcolm Stewart ... new file is mypic.jpg instead of mypic.heic.jpg
$outFileName = "$($inputFolder.Path)\$outputFileName"**
finally
{
# Clean-up
if ($inputStream -ne $null) { [System.IDisposable]$inputStream.Dispose() }
if ($outputStream -ne $null) { [System.IDisposable]$outputStream.Dispose() }
**if ($outFileName -ne "")
{
(Get-Item $outFileName).CreationTime = $fileCreateDate # Malcolm Stewart
(Get-Item $outFileName).LastWriteTime = $fileModifiedDate # Malcolm Stewart
}**
MarkDown seems to see the code as code, so Bold asterisks are still in there without the formatting