Friday, April 19, 2024
HomePowershellPicture Manipulation, Picture Resize, Picture Mix and extra with PowerShell

Picture Manipulation, Picture Resize, Picture Mix and extra with PowerShell


ImagePlaground might be useful for its potential to Mix, Resize or Convert photos between codecs. All of it will be carried out utilizing ConvertTo-Picture, Resize-Picture, and Merge-Picture PowerShell capabilities. These capabilities are elementary to make use of with only a few parameters.

ConvertTo-Picture -FilePath $PSScriptRootSamplesLogoEvotec.png -OutputPath $PSScriptRootOutputLogoEvotec.jpg

ConvertTo-Picture takes two parameters enter path and output path. Relying on the file’s extension, it would attempt to convert to a given sort. It helps following varieties:

  • JPG/JPEG
  • BMP
  • GIF
  • PBM
  • TGA
  • TIFF
  • WEBP

Merge-Picture could be very related. It has 5 parameters, however solely three are necessary. It requires FilePath, FilePathToMerge, and FilePathOutput. This ensures that two photos are merged and utilized to the underside of the primary picture. After all, a brand new picture is created, leaving the opposite two untouched. There are additionally two extra parameters. One is ResizeToFit which ensures that the smaller picture is resized to match the sting of the bigger image. After all, it is not mandatory, however then relying on the scale of the picture, the merge might not look nice.

However, resizing a picture might trigger show points. The picture is resized proportionally on each edges to keep up the facet ratio. There’s additionally a Placement parameter that decides the place the pictures bind collectively. By default, the binding is completed on the underside of the primary picture however you may select Left, Proper, Backside or Prime.

$mergeImageSplat = @{
    FilePath        = "$PSScriptRootSamplesBarcodeEAN13.png"
    FilePathToMerge = "$PSScriptRootSamplesBarcodeEAN7.png"
    FilePathOutput  = "$PSScriptRootOutputBarcodeEAN13-7.png"
    ResizeToFit     = $true
    Placement="Backside"
}

Merge-Picture @mergeImageSplat


$mergeImageSplat = @{
    FilePath        = "$PSScriptRootSamplesChartsBar.png"
    FilePathToMerge = "$PSScriptRootSamplesLogoEvotec.png"
    FilePathOutput  = "$PSScriptRootOutputMergedImage.png"
    ResizeToFit     = $true
    Placement="Left"
}

Merge-Picture @mergeImageSplat

For show functions, I am utilizing splatting to point out all parameters. Lastly, we’ve got the Resize-Picture perform, which supplies a simple solution to resize any picture both by Width or Top, or each Width and Top, or by proportion.

Resize-Picture -FilePath $PSScriptRootSamplesLogoEvotec.png -OutputPath $PSScriptRootOutputLogoEvotecResize.png -Width 100 -Top 100

Resize-Picture -FilePath $PSScriptRootSamplesLogoEvotec.png -OutputPath $PSScriptRootOutputLogoEvotecResizeMaintainAspectRatio.png -Width 300

Resize-Picture -FilePath $PSScriptRootSamplesLogoEvotec.png -OutputPath $PSScriptRootOutputLogoEvotecResizeMaintainAspectRatio.png -Width 300 -DontRespectAspectRatio

Resize-Picture -FilePath $PSScriptRootSamplesLogoEvotec.png -OutputPath $PSScriptRootOutputLogoEvotecResizePercent.png -Proportion 200

When the proportion is in use, the facet ratio is at all times preserved. If each Width and Top are offered concurrently, the perform assumes you already know what you need and what you are doing. If solely width or top is offered, it would resize the picture appropriately to make sure it suits the given edge however then respect the facet ratio to make sure the picture scales nicely. Lastly, there’s the DontRespectAspectRatio parameter which matches together with Width or Top and means that you can change just one edge if that is your need.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments