Moved common var to common package

This commit is contained in:
Samuel Hawksby-Robinson 2020-09-18 15:47:44 +01:00
parent c32b7ad8e3
commit 444a435402
No known key found for this signature in database
GPG Key ID: 64CF99D4A64A1205
4 changed files with 10 additions and 6 deletions

3
common/main.go Normal file
View File

@ -0,0 +1,3 @@
package common
var ImageDir = "images/"

View File

@ -7,6 +7,8 @@ import (
"log" "log"
"os" "os"
"strconv" "strconv"
"github.com/status-im/image_resizer/common"
) )
func getImage(fileName string) image.Image { func getImage(fileName string) image.Image {
@ -44,10 +46,8 @@ func makeReadMe(imgDs map[string][]imageDetails) {
var txt string var txt string
for _, imageName := range images { for _, imageName := range images {
fn := imageDir + imageName + ".jpg"
txt += "## " + imageName + "\n\n" txt += "## " + imageName + "\n\n"
txt += fmt.Sprintf("![Original %s image](%s)\n\n", imageName, fn) txt += fmt.Sprintf("![Original %s image](%s)\n\n", imageName, common.ImageDir + imageName + ".jpg")
txt += "| Image | Properties | Size (px^2) | Image Quality (%) | Size (bytes) |\n" txt += "| Image | Properties | Size (px^2) | Image Quality (%) | Size (bytes) |\n"
txt += "| :---: | ---------- | ----------: | ----------------: | -----------: |\n" txt += "| :---: | ---------- | ----------: | ----------------: | -----------: |\n"

View File

@ -3,6 +3,8 @@ package main
import ( import (
"fmt" "fmt"
"strings" "strings"
"github.com/status-im/image_resizer/common"
) )
type imageDetails struct { type imageDetails struct {
@ -14,14 +16,14 @@ type imageDetails struct {
} }
func getSourceImageName(imageName string) string { func getSourceImageName(imageName string) string {
return imageDir + imageName + ".jpg" return common.ImageDir + imageName + ".jpg"
} }
func makeOutputImageName(imageName string, size uint, i int, properties string) string { func makeOutputImageName(imageName string, size uint, i int, properties string) string {
if properties != "" { if properties != "" {
properties = "_" + strings.ReplaceAll(properties, " ", "-") properties = "_" + strings.ReplaceAll(properties, " ", "-")
} }
return fmt.Sprintf(imageDir + "%s_s-%d_q-%d%s.jpg", imageName, size, i, properties) return fmt.Sprintf(common.ImageDir + "%s_s-%d_q-%d%s.jpg", imageName, size, i, properties)
} }
func makeImageDetails(imageName string, size uint, quality int, properties string) imageDetails { func makeImageDetails(imageName string, size uint, quality int, properties string) imageDetails {

View File

@ -5,7 +5,6 @@ import (
) )
var ( var (
imageDir = "images/"
images = []string{ images = []string{
"elephant", "elephant",
"frog", "frog",