This is a powershell script to convert tif files to jpg format or png format. It takes folder path as input. Searches the folder for .tif files and converts all of them to png/jpg(specified as input) and stores in the same folder)
C:\odm_orthophoto\odm_orthophoto_render.tif
Cannot convert argument "format", with value: "jpg", for "Save" to type "System.Drawing.Imaging.ImageFormat": "Cannot convert value "jpg" to type "System.Drawing.Imaging.ImageFormat". Error: "ImageFormatConverter cannot convert from System.String.""
At C:\odm_orthophoto\convert.ps1:22 char:4
$convertfile.Save($newfilname, $jpgOrpng)
CategoryInfo : NotSpecified: (:) [], MethodException
FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
This is running on Windows 10 PowerShell.
PSVersion 5.1.19041.3031
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.3031
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
The solution is actually quite simple. While 'jpg' is not recognized, you can use 'jpeg' and that will convert properly from GeoTiff to JPEG file format.
ConvertImage -path '.' -jpgOrpng 'jpg'
C:\odm_orthophoto\odm_orthophoto_render.tif Cannot convert argument "format", with value: "jpg", for "Save" to type "System.Drawing.Imaging.ImageFormat": "Cannot convert value "jpg" to type "System.Drawing.Imaging.ImageFormat". Error: "ImageFormatConverter cannot convert from System.String."" At C:\odm_orthophoto\convert.ps1:22 char:4 $convertfile.Save($newfilname, $jpgOrpng)