{"id":109,"date":"2017-04-22T20:55:42","date_gmt":"2017-04-22T18:55:42","guid":{"rendered":"http:\/\/powershell24.de\/?p=109"},"modified":"2018-05-13T21:47:50","modified_gmt":"2018-05-13T19:47:50","slug":"set-imagesize","status":"publish","type":"post","link":"https:\/\/powershell24.de\/en\/2017\/04\/22\/set-imagesize\/","title":{"rendered":"Bildergr\u00f6\u00dfe anpassen"},"content":{"rendered":"<p>Folgendes Skript ist NICHT von mir. Die Credits gehen an Michal Gajda von commandlinegeeks.com!<\/p>\n<p>Ich\u00a0benutze es jedoch sehr gerne, vor allem wen es darum geht die AD-User-Bilder nach erfolgreichem Export weiter zu verarbeiten.<\/p>\n<pre class=\"lang:ps decode:true\" title=\"Set-ImageSize\">Function Set-ImageSize\r\n{\r\n    &lt;#\r\n\t.SYNOPSIS\r\n\t    Resize image file.\r\n\r\n\t.DESCRIPTION\r\n\t    The Set-ImageSize cmdlet to set new size of image file.\r\n\t\t\r\n\t.PARAMETER Image\r\n\t    Specifies an image file. \r\n\r\n\t.PARAMETER Destination\r\n\t    Specifies a destination of resized file. Default is current location (Get-Location).\r\n\t\r\n\t.PARAMETER WidthPx\r\n\t    Specifies a width of image in px. \r\n\t\t\r\n\t.PARAMETER HeightPx\r\n\t    Specifies a height of image in px.\t\t\r\n\t\r\n\t.PARAMETER DPIWidth\r\n\t    Specifies a vertical resolution. \r\n\t\t\r\n\t.PARAMETER DPIHeight\r\n\t    Specifies a horizontal resolution.\t\r\n\t\t\r\n\t.PARAMETER Overwrite\r\n\t    Specifies a destination exist then overwrite it without prompt. \r\n\t\t\r\n\t.PARAMETER FixedSize\r\n\t    Set fixed size and do not try to scale the aspect ratio. \r\n\r\n\t.PARAMETER RemoveSource\r\n\t    Remove source file after conversion. \r\n\t\t\r\n\t.EXAMPLE\r\n\t\tPS C:\\&gt; Get-ChildItem 'P:\\test\\*.jpg' | Set-ImageSize -Destination \"p:\\test2\" -WidthPx 300 -HeightPx 375 -Verbose\r\n\t\tVERBOSE: Image 'P:\\test\\00001.jpg' was resize from 236x295 to 300x375 and save in 'p:\\test2\\00001.jpg'\r\n\t\tVERBOSE: Image 'P:\\test\\00002.jpg' was resize from 236x295 to 300x375 and save in 'p:\\test2\\00002.jpg'\r\n\t\tVERBOSE: Image 'P:\\test\\00003.jpg' was resize from 236x295 to 300x375 and save in 'p:\\test2\\00003.jpg'\r\n\t\t\r\n\t.NOTES\r\n\t\tAuthor: Michal Gajda\r\n\t\tBlog  : http:\/\/commandlinegeeks.com\/\r\n\t#&gt;\r\n\t[CmdletBinding(\r\n    \tSupportsShouldProcess=$True,\r\n        ConfirmImpact=\"Low\"\r\n    )]\t\t\r\n\tParam\r\n\t(\r\n\t\t[parameter(Mandatory=$true,\r\n\t\t\tValueFromPipeline=$true,\r\n\t\t\tValueFromPipelineByPropertyName=$true)]\r\n\t\t[Alias(\"Image\")]\t\r\n\t\t[String[]]$FullName,\r\n\t\t[String]$Destination = $(Get-Location),\r\n\t\t[Switch]$Overwrite,\r\n\t\t[Int]$WidthPx,\r\n\t\t[Int]$HeightPx,\r\n\t\t[Int]$DPIWidth,\r\n\t\t[Int]$DPIHeight,\r\n\t\t[Switch]$FixedSize,\r\n\t\t[Switch]$RemoveSource\r\n\t)\r\n\r\n\tBegin\r\n\t{\r\n\t\t[void][reflection.assembly]::LoadWithPartialName(\"System.Windows.Forms\")\r\n\t\t#[void][reflection.assembly]::loadfile( \"C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\System.Drawing.dll\")\r\n\t}\r\n\t\r\n\tProcess\r\n\t{\r\n\r\n\t\tForeach($ImageFile in $FullName)\r\n\t\t{\r\n\t\t\tIf(Test-Path $ImageFile)\r\n\t\t\t{\r\n\t\t\t\t$OldImage = new-object System.Drawing.Bitmap $ImageFile\r\n\t\t\t\t$OldWidth = $OldImage.Width\r\n\t\t\t\t$OldHeight = $OldImage.Height\r\n\t\t\t\t\r\n\t\t\t\tif($WidthPx -eq $Null)\r\n\t\t\t\t{\r\n\t\t\t\t\t$WidthPx = $OldWidth\r\n\t\t\t\t}\r\n\t\t\t\tif($HeightPx -eq $Null)\r\n\t\t\t\t{\r\n\t\t\t\t\t$HeightPx = $OldHeight\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif($FixedSize)\r\n\t\t\t\t{\r\n\t\t\t\t\t$NewWidth = $WidthPx\r\n\t\t\t\t\t$NewHeight = $HeightPx\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif($OldWidth -lt $OldHeight)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t$NewWidth = $WidthPx\r\n\t\t\t\t\t\t[int]$NewHeight = [Math]::Round(($NewWidth*$OldHeight)\/$OldWidth)\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tif($NewHeight -gt $HeightPx)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t$NewHeight = $HeightPx\r\n\t\t\t\t\t\t\t[int]$NewWidth = [Math]::Round(($NewHeight*$OldWidth)\/$OldHeight)\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t$NewHeight = $HeightPx\r\n\t\t\t\t\t\t[int]$NewWidth = [Math]::Round(($NewHeight*$OldWidth)\/$OldHeight)\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tif($NewWidth -gt $WidthPx)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t$NewWidth = $WidthPx\r\n\t\t\t\t\t\t\t[int]$NewHeight = [Math]::Round(($NewWidth*$OldHeight)\/$OldWidth)\r\n\t\t\t\t\t\t}\t\t\t\t\t\t\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t$ImageProperty = Get-ItemProperty $ImageFile\t\t\t\t\r\n\t\t\t\t$SaveLocation = Join-Path -Path $Destination -ChildPath ($ImageProperty.Name)\r\n\r\n\t\t\t\tIf(!$Overwrite)\r\n\t\t\t\t{\r\n\t\t\t\t\tIf(Test-Path $SaveLocation)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t$Title = \"A file already exists: $SaveLocation\"\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t$ChoiceOverwrite = New-Object System.Management.Automation.Host.ChoiceDescription \"&amp;Overwrite\"\r\n\t\t\t\t\t\t$ChoiceCancel = New-Object System.Management.Automation.Host.ChoiceDescription \"&amp;Cancel\"\r\n\t\t\t\t\t\t$Options = [System.Management.Automation.Host.ChoiceDescription[]]($ChoiceCancel, $ChoiceOverwrite)\t\t\r\n\t\t\t\t\t\tIf(($host.ui.PromptForChoice($Title, $null, $Options, 1)) -eq 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tWrite-Verbose \"Image '$ImageFile' exist in destination location - skiped\"\r\n\t\t\t\t\t\t\tContinue\r\n\t\t\t\t\t\t} #End If ($host.ui.PromptForChoice($Title, $null, $Options, 1)) -eq 0\r\n\t\t\t\t\t} #End If Test-Path $SaveLocation\r\n\t\t\t\t} #End If !$Overwrite\t\r\n\t\t\t\t\r\n\t\t\t\t$NewImage = new-object System.Drawing.Bitmap $NewWidth,$NewHeight\r\n\r\n\t\t\t\t$Graphics = [System.Drawing.Graphics]::FromImage($NewImage)\r\n\t\t\t\t$Graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic\r\n\t\t\t\t$Graphics.DrawImage($OldImage, 0, 0, $NewWidth, $NewHeight) \r\n\r\n\t\t\t\t$ImageFormat = $OldImage.RawFormat\r\n\t\t\t\t$OldImage.Dispose()\r\n\t\t\t\tif($DPIWidth -and $DPIHeight)\r\n\t\t\t\t{\r\n\t\t\t\t\t$NewImage.SetResolution($DPIWidth,$DPIHeight)\r\n\t\t\t\t} #End If $DPIWidth -and $DPIHeight\r\n\t\t\t\t\r\n\t\t\t\t$NewImage.Save($SaveLocation,$ImageFormat)\r\n\t\t\t\t$NewImage.Dispose()\r\n\t\t\t\tWrite-Verbose \"Image '$ImageFile' was resize from $($OldWidth)x$($OldHeight) to $($NewWidth)x$($NewHeight) and save in '$SaveLocation'\"\r\n\t\t\t\t\r\n\t\t\t\tIf($RemoveSource)\r\n\t\t\t\t{\r\n\t\t\t\t\tRemove-Item $Image -Force\r\n\t\t\t\t\tWrite-Verbose \"Image source '$ImageFile' was removed\"\r\n\t\t\t\t} #End If $RemoveSource\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t} #End Process\r\n\t\r\n\tEnd{}\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Folgendes Skript ist NICHT von mir. Die Credits gehen an Michal Gajda von commandlinegeeks.com! Ich\u00a0benutze es jedoch sehr gerne, vor allem wen es darum geht die AD-User-Bilder nach erfolgreichem Export weiter zu verarbeiten. Function Set-ImageSize { &lt;# .SYNOPSIS Resize image file. .DESCRIPTION The Set-ImageSize cmdlet to set new size of image file. .PARAMETER Image Specifies <a href=\"https:\/\/powershell24.de\/en\/2017\/04\/22\/set-imagesize\/\" rel=\"nofollow\"><span class=\"sr-only\">Read more about Bildergr\u00f6\u00dfe anpassen<\/span>[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[22,25,24,21,23],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-snippets","tag-image","tag-jpg","tag-picture","tag-resize","tag-size"],"translation":{"provider":"WPGlobus","version":"3.0.1","language":"en","enabled_languages":["de","en"],"languages":{"de":{"title":true,"content":true,"excerpt":false},"en":{"title":false,"content":false,"excerpt":false}}},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":3,"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":188,"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/posts\/109\/revisions\/188"}],"wp:attachment":[{"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/powershell24.de\/en\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}