Skip to content

Commit 6633d61

Browse files
committed
format and quality option
1 parent ab8400c commit 6633d61

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

help.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ func help() {
1313
-i input_directory
1414
-o output_directory (defaults to ./out)
1515
-r rough_height (defaults to 5000)
16-
16+
-f output_format [jpeg|jpg|png] (defaults to jpeg)
17+
-q jpeg_quality (defaults to 100)
18+
1719
%s
1820
-a: use absolute height (defaults to false)
19-
21+
2022
%s
2123
-n neighbor_count (defaults to 5)
2224
-s skip_step (defaults to 5)
@@ -26,7 +28,7 @@ func help() {
2628
https://github.com/manas140/seam/issues
2729
%s`, col("Seam",
2830
34),
29-
col("v0.0.1", 2),
31+
col("v0.0.2", 2),
3032
col("General:", 32),
3133
col("Toggle:", 36),
3234
col("Advanced:", 35),

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func main() {
4343
format string = "jpeg"
4444
skipStep int = 5
4545
neighborCount int = 5
46+
quality int = 100
4647
)
4748

4849
// get arguments
@@ -71,6 +72,8 @@ func main() {
7172
}
7273
i++
7374
format = args[i]
75+
case "-q":
76+
i = checkArgs("quality", args, &quality, i)
7477
case "-s":
7578
i = checkArgs("skip step", args, &skipStep, i)
7679
case "-n":
@@ -165,7 +168,7 @@ func main() {
165168
var wg sync.WaitGroup
166169
wg.Add(len(slicedImg))
167170
for i, img := range slicedImg {
168-
go saveImage(img, fmt.Sprintf("%s/%d.%s", outputDir, i, format), format, &wg)
171+
go saveImage(img, fmt.Sprintf("%s/%d.%s", outputDir, i, format), format, quality, &wg)
169172
}
170173
wg.Wait()
171174
out.Debug("Took %.2fs", time.Since(start).Seconds())

utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func readImage(path string) (image.Image, error) {
4040
return img, nil
4141
}
4242

43-
func saveImage(img image.Image, path string, ext string, wg *sync.WaitGroup) {
43+
func saveImage(img image.Image, path string, ext string, quality int, wg *sync.WaitGroup) {
4444
file, err := os.Create(path)
4545
if err != nil {
4646
out.Error("Unable to create file '%s'", path)
@@ -51,7 +51,7 @@ func saveImage(img image.Image, path string, ext string, wg *sync.WaitGroup) {
5151
case "png":
5252
png.Encode(file, img)
5353
default:
54-
jpeg.Encode(file, img, nil)
54+
jpeg.Encode(file, img, &jpeg.Options{Quality: quality})
5555
}
5656
wg.Done()
5757
}

0 commit comments

Comments
 (0)