-
Notifications
You must be signed in to change notification settings - Fork 3
Add option to write to STDOUT #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ArtOfCode-
wants to merge
1
commit into
balpha:main
Choose a base branch
from
ArtOfCode-:art/write-to-stdout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -2,22 +2,24 @@ package main | |
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"crypto/md5" | ||
"encoding/hex" | ||
"flag" | ||
"fmt" | ||
"github.com/balpha/go-unicornify/unicornify" | ||
"image" | ||
"image/png" | ||
"math/rand" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/balpha/go-unicornify/unicornify" | ||
) | ||
|
||
func main() { | ||
var mail, hash string | ||
var random, free, zoomOut, nodouble, noshading, nograss, serial bool | ||
var random, free, zoomOut, nodouble, noshading, nograss, serial, writeStdout bool | ||
var size int | ||
var outfile string | ||
|
||
|
@@ -32,6 +34,7 @@ func main() { | |
flag.BoolVar(&noshading, "noshading", false, "do not add shading, this will make unicorns look flatter") | ||
flag.BoolVar(&nograss, "nograss", false, "do not add grass to the ground") | ||
flag.BoolVar(&serial, "serial", false, "do not parallelize the drawing") | ||
flag.BoolVar(&writeStdout, "stdout", false, "write image to STDOUT") | ||
|
||
flag.Parse() | ||
inputs := 0 | ||
|
@@ -66,7 +69,10 @@ func main() { | |
outfile = hash + ".png" | ||
} | ||
|
||
fmt.Printf("Creating size %v avatar for hash %v, writing into %v\n", size, hash, outfile) | ||
if !writeStdout { | ||
fmt.Printf("Creating size %v avatar for hash %v, writing into %v\n", size, hash, outfile) | ||
} | ||
Comment on lines
+72
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just send this to stderr instead of disabling it. Not sure why I sent this to stdout and the rest to stderr -- it should all go to stderr. |
||
|
||
actualSize := size | ||
if !nodouble { | ||
actualSize *= 2 | ||
|
@@ -88,6 +94,18 @@ func main() { | |
img = downscale(img) | ||
} | ||
|
||
if writeStdout { | ||
buf := new(bytes.Buffer) | ||
err := png.Encode(buf, img) | ||
if err != nil { | ||
os.Stderr.WriteString("Error encoding to PNG\n") | ||
os.Exit(1) | ||
} | ||
|
||
os.Stdout.Write(buf.Bytes()) | ||
return | ||
} | ||
|
||
f, err := os.Create(outfile) | ||
if err != nil { | ||
os.Stderr.WriteString("Could not create output file " + outfile + "\n") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change the info message (see my other comment) to go to stderr instead of stdout, then it seems like this option isn't necessary anymore, since you can specify stdout as the outfile.
At least on my machine, this works fine:
What do you think?