PoshCode Archive  Artifact [c2bbb296dc]

Artifact c2bbb296dc3cbb94810edadf79352aa1d4a1fb6860394d6d553bc691aa2e2e68:

  • File Resize-Image.ps1 — part of check-in [89e0b9ee25] at 2018-06-10 13:03:53 on branch trunk — A simple image resizer … (user: Joel Bennett size: 1215)

# encoding: ascii
# api: powershell
# title: Resize-Image
# description: A simple image resizer …
# version: 0.25
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 2000
# x-archived: 2016-03-05T01:40:08
# x-published: 2011-07-21T09:39:00
#
#
## NOTE: Destination must end in .bmp, .gif, .png, .wmp, .jpeg or .tiff
param($source = "C:\Windows\Web\Wallpaper\Windows\img0.jpg", $destination = "$Home\Pictures\thumb0.png", $scale = 0.25)
Add-Type -Assembly PresentationCore

## Open and resize the image
$image = New-Object System.Windows.Media.Imaging.TransformedBitmap (New-Object System.Windows.Media.Imaging.BitmapImage $source),
                                                                   (New-Object System.Windows.Media.ScaleTransform $scale,$scale)
## Put it on the clipboard (just for fun)
[System.Windows.Clipboard]::SetImage( $image )

## Write out an image file:
$stream = [System.IO.File]::Open($destination, "OpenOrCreate")
$encoder = New-Object System.Windows.Media.Imaging.$([IO.Path]::GetExtension($destination).substring(1))BitmapEncoder
$encoder.Frames.Add([System.Windows.Media.Imaging.BitmapFrame]::Create($image))
$encoder.Save($stream)
$stream.Dispose()