-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rebelinux/dev
v0.1.8 public release
- Loading branch information
Showing
29 changed files
with
1,320 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
name: Bug Report | ||
description: File a bug report | ||
title: "[BUG]" | ||
labels: ["bug"] | ||
assignees: rebelinux | ||
body: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
function Add-WatermarkToImage { | ||
<# | ||
.SYNOPSIS | ||
Used to add a watermark text to Image | ||
.DESCRIPTION | ||
Takes a string and add it as an 45 degree watermakr to the provided Image file. | ||
.Example | ||
Add-WatermarkToImage ImageInput "c:\Image.png" DestinationPath "c:\Image_Edited.png" -WaterMarkText "Zen PR Solutions" -FontName 'Arial' -FontSize 20 -FontColor 'Red' | ||
.NOTES | ||
Version: 0.1.8 | ||
Author: Jonathan Colon | ||
Twitter: @jcolonfzenpr | ||
Github: rebelinux | ||
.PARAMETER ImageInputFile | ||
The Image file Path (PNG, TIFF, JPEG, JPG) | ||
.PARAMETER Base64Input | ||
The image in base64 format | ||
.PARAMETER ImageOutputFile | ||
The path of the resulting edited image | ||
.PARAMETER WaterMarkText | ||
The text to be inserted to the image as a watermark | ||
.PARAMETER FontName | ||
The font name | ||
.PARAMETER FontSize | ||
The font size | ||
.PARAMETER FontColor | ||
The font color [System.Drawing.Color] type (Red, Blue, Yellow etc..) | ||
.PARAMETER FontOpacity | ||
The font color opacity level | ||
#> | ||
|
||
param( | ||
[Parameter( | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide the path to the image file path' | ||
)] | ||
[ValidateScript( { | ||
if (Test-Path -Path $_) { | ||
$true | ||
} else { | ||
throw "File $_ not found!" | ||
} | ||
})] | ||
[string] $ImageInput, | ||
|
||
[Parameter( | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide the complete filepath to export the diagram' | ||
)] | ||
[string] $DestinationPath, | ||
|
||
[Parameter( | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide the text to transform' | ||
)] | ||
[ValidateNotNullOrEmpty()] | ||
[string] $WaterMarkText, | ||
|
||
[string] $FontName = 'Arial', | ||
|
||
[int] $FontSize = 180, | ||
|
||
[System.Drawing.Color] $FontColor = 'Red', | ||
|
||
[int] $FontOpacity = 20 | ||
) | ||
|
||
begin { | ||
# Initialize .net assemblies | ||
Add-Type -AssemblyName System.Windows.Forms | ||
} | ||
|
||
process { | ||
|
||
$ImageName = Get-ChildItem -Path $ImageInput | ||
# Teporary Image file name | ||
$FileName = $ImageName.BaseName + "_WaterMark" + $ImageName.Extension | ||
|
||
# Get the image from the ImageInput path | ||
$Bitmap = [System.Drawing.Image]::FromFile($ImageName.FullName) | ||
|
||
# Teporary Image file path | ||
$TempImageOutput = Join-Path -Path ([system.io.path]::GetTempPath()) -ChildPath $FileName | ||
|
||
# Initialize the font properties and brush | ||
$FontType = [System.Drawing.Font]::new($FontName, $FontSize, [System.Drawing.FontStyle]::Italic, [System.Drawing.GraphicsUnit]::Pixel, [System.Drawing.GraphicsUnit]::Bold) | ||
$FontColor = [System.Drawing.Color]::FromArgb($FontOpacity, $FontColor) | ||
$SolidBrush = [System.Drawing.SolidBrush]::new($FontColor) | ||
|
||
If ($Bitmap, $FontType, $FontColor, $SolidBrush) { | ||
|
||
# Get the center of the image | ||
$Grid = [System.Drawing.Point]::new($Bitmap.Width / 2, $Bitmap.Height / 2) | ||
$Graphics = [System.Drawing.Graphics]::FromImage($Bitmap) | ||
|
||
# Set the properties to allow the text to be centered | ||
$StringFormat = [System.Drawing.StringFormat]::new() | ||
$StringFormat.Alignment = [System.Drawing.StringAlignment]::Center | ||
$StringFormat.LineAlignment = [System.Drawing.StringAlignment]::Center | ||
$StringFormat.FormatFlags = [System.Drawing.StringFormatFlags]::MeasureTrailingSpaces | ||
|
||
# Get the center of the image used to rotate the text in a -45 angle | ||
$Graphics.TranslateTransform($Bitmap.Width / 2, $Bitmap.Height / 2) | ||
$Graphics.RotateTransform(-45) | ||
|
||
# Apply the properties to the Bitmap | ||
$Graphics.DrawString($WaterMarkText, $FontType, $SolidBrush, - ($Grid.Width / 2), - ($Grid.Height / 2), $StringFormat) | ||
# Destroy the graphics object | ||
$Graphics.Dispose() | ||
|
||
} else { | ||
Write-Information "Unable to add watermark to image!" | ||
} | ||
} | ||
|
||
end { | ||
try { | ||
# Save the Image to path define in $TempImageOutput | ||
$Bitmap.Save($TempImageOutput) | ||
# Destroy the Bitmap object | ||
$Bitmap.Dispose() | ||
|
||
if ($TempImageOutput) { | ||
Write-Verbose "Successfully added watermark text to $ImageInput image." | ||
if ($PSBoundParameters.ContainsKey('DestinationPath')) { | ||
try { | ||
Copy-Item -Path $TempImageOutput -Destination $DestinationPath | ||
Write-Verbose "Successfully replaced $DestinationPath with $TempImageOutput rotated image." | ||
} catch { | ||
Write-Verbose "Unable to replace $DestinationPath rotated image to $TempImageOutput diagram." | ||
Write-Verbose $($_.Exception.Message) | ||
} | ||
} else { | ||
Write-Verbose "Successfully rotated $ImageInput diagram." | ||
Get-ChildItem -Path $TempImageOutput | ||
} | ||
} | ||
|
||
} catch { | ||
$PSCmdlet.ThrowTerminatingError($PSitem) | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function ConvertTo-Base64 { | ||
<# | ||
.SYNOPSIS | ||
Function to export diagram to base64 format. | ||
.DESCRIPTION | ||
Export a diagram in PDF/PNG/SVG formats using PSgraph. | ||
.NOTES | ||
Version: 0.1.8 | ||
Author: Jonathan Colon | ||
Twitter: @jcolonfzenpr | ||
Github: rebelinux | ||
.LINK | ||
https://github.com/rebelinux/Diagrammer.Core | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
Param | ||
( | ||
[Parameter( | ||
Position = 0, | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide image file path' | ||
)] | ||
[ValidateScript( { | ||
if (Test-Path -Path $_) { | ||
$true | ||
} else { | ||
throw "File $_ not found!" | ||
} | ||
})] | ||
[string] $ImageInput | ||
) | ||
process { | ||
Write-Verbose "Trying to convert Graphviz object to Base64 format." | ||
# Code used to output image to base64 format | ||
try { | ||
$Base64 = [convert]::ToBase64String((Get-Content $ImageInput -Encoding byte)) | ||
} catch { | ||
Write-Verbose "Unable to convert Graphviz object to Base64 format." | ||
Write-Verbose $($_.Exception.Message) | ||
} | ||
if ($Base64) { | ||
Write-Verbose -Message "Deleting Temporary PNG file: $($ImageInput)" | ||
Remove-Item -Path $ImageInput | ||
Write-Verbose "Successfully converted Graphviz object to Base64 format." | ||
$Base64 | ||
} else { | ||
Write-Verbose -Message "Deleting Temporary PNG file: $($ImageInput)" | ||
Remove-Item -Path $ImageInput | ||
} | ||
} | ||
end {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function ConvertTo-Dot { | ||
<# | ||
.SYNOPSIS | ||
Function to export diagram to dot format. | ||
.DESCRIPTION | ||
Export a diagram in PDF/PNG/SVG formats using PSgraph. | ||
.NOTES | ||
Version: 0.1.8 | ||
Author: Jonathan Colon | ||
Twitter: @jcolonfzenpr | ||
Github: rebelinux | ||
.LINK | ||
https://github.com/rebelinux/Diagrammer.Core | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
Param | ||
( | ||
[Parameter( | ||
Position = 0, | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide the graphviz dot object' | ||
)] | ||
$GraphObj, | ||
[Parameter( | ||
Position = 1, | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide the file path to export the diagram' | ||
)] | ||
[string] $DestinationPath | ||
) | ||
process { | ||
if ($WaterMarkText) { | ||
Write-ColorOutput -Color 'Red' -String "WaterMark option is not supported with the dot format." | ||
} | ||
|
||
try { | ||
Write-Verbose "Trying to convert Graphviz object to DOT format. Destination Path: $DestinationPath." | ||
$Document = Export-PSGraph -Source $GraphObj -DestinationPath $DestinationPath -OutputFormat 'dot' -GraphVizPath $GraphvizPath | ||
} catch { | ||
Write-Verbose "Unable to convert Graphviz object to DOT format." | ||
Write-Verbose $($_.Exception.Message) | ||
} | ||
if ($Document) { | ||
if ($Document) { | ||
Write-Verbose "Successfully converted Graphviz object to DOT format. Saved Path: $DestinationPath." | ||
Get-ChildItem -Path $Document | ||
} | ||
} | ||
} | ||
end {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function ConvertTo-Pdf { | ||
<# | ||
.SYNOPSIS | ||
Function to export diagram to pdf format. | ||
.DESCRIPTION | ||
Export a diagram in PDF/PNG/SVG formats using PSgraph. | ||
.NOTES | ||
Version: 0.1.8 | ||
Author: Jonathan Colon | ||
Twitter: @jcolonfzenpr | ||
Github: rebelinux | ||
.LINK | ||
https://github.com/rebelinux/Diagrammer.Core | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
Param | ||
( | ||
[Parameter( | ||
Position = 0, | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide the graphviz dot object' | ||
)] | ||
$GraphObj, | ||
[Parameter( | ||
Position = 1, | ||
Mandatory = $true, | ||
HelpMessage = 'Please provide the file path to export the diagram' | ||
)] | ||
[string] $DestinationPath | ||
) | ||
process { | ||
try { | ||
Write-Verbose "Trying to convert Graphviz object to PDF format. Destination Path: $DestinationPath." | ||
$Document = Export-PSGraph -Source $GraphObj -DestinationPath $DestinationPath -OutputFormat 'pdf' -GraphVizPath $GraphvizPath | ||
} catch { | ||
Write-Verbose "Unable to convert Graphviz object to PNG format." | ||
Write-Verbose $($_.Exception.Message) | ||
} | ||
if ($Document) { | ||
if ($Document) { | ||
Write-Verbose "Successfully converted Graphviz object to PDF format. Saved Path: $DestinationPath." | ||
Get-ChildItem -Path $Document | ||
} | ||
} | ||
} | ||
end {} | ||
} |
Oops, something went wrong.