|
|
|
|
@ -39,35 +39,38 @@ func SaveImage(filename string, img image.Image) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func AdjustDim(src_dim int, setting_dim int) int { |
|
|
|
|
// BUG: should use the aspect ratio
|
|
|
|
|
if setting_dim == 0 { |
|
|
|
|
return src_dim |
|
|
|
|
} else { |
|
|
|
|
return setting_dim |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func JankImage(settings Conversion, in_file string, out_file string) { |
|
|
|
|
src := LoadImage(in_file) |
|
|
|
|
src_bounds := src.Bounds() |
|
|
|
|
target_bounds := src_bounds |
|
|
|
|
var target_bounds image.Rectangle |
|
|
|
|
|
|
|
|
|
if settings.Width > 0 { |
|
|
|
|
target_bounds.Max.X = settings.Width |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if settings.Height > 0 { |
|
|
|
|
target_bounds.Max.Y = settings.Height |
|
|
|
|
} |
|
|
|
|
target_bounds.Max.X = AdjustDim(src_bounds.Max.X, settings.Width) |
|
|
|
|
target_bounds.Max.Y = AdjustDim(src_bounds.Max.Y, settings.Height) |
|
|
|
|
|
|
|
|
|
fmt.Println("final size is: ", target_bounds.Max.X, target_bounds.Max.Y) |
|
|
|
|
|
|
|
|
|
// only done when shrinking/growing
|
|
|
|
|
presize := gift.Resize(target_bounds.Max.X, target_bounds.Max.Y, gift.NearestNeighborResampling) |
|
|
|
|
|
|
|
|
|
resize := gift.Resize(target_bounds.Max.X / settings.PixelWidth, 0, gift.NearestNeighborResampling) |
|
|
|
|
posterize := filters.Posterize(uint16(settings.ColorDepth), settings.DitherType) |
|
|
|
|
upscale := filters.Upscale(target_bounds, settings.PixelWidth) |
|
|
|
|
// BUG: use the shortest dimension for the pixelate, or add a framesize setting
|
|
|
|
|
resize := gift.Resize(src_bounds.Max.X / settings.PixelWidth, 0, gift.NearestNeighborResampling) |
|
|
|
|
// posterize := filters.Posterize(uint16(settings.ColorDepth), settings.DitherType)
|
|
|
|
|
upscale := filters.Upscale(src_bounds, settings.PixelWidth) |
|
|
|
|
final_size := gift.Resize(target_bounds.Max.X, target_bounds.Max.Y, gift.NearestNeighborResampling) |
|
|
|
|
sharpen := gift.UnsharpMask(1, 1, 0) |
|
|
|
|
|
|
|
|
|
var g *gift.GIFT |
|
|
|
|
|
|
|
|
|
if target_bounds.Max.X != src_bounds.Max.X || target_bounds.Max.Y != src_bounds.Max.Y { |
|
|
|
|
g = gift.New(presize, resize, posterize, upscale, sharpen) |
|
|
|
|
g = gift.New(resize, upscale, sharpen, final_size) |
|
|
|
|
} else { |
|
|
|
|
g = gift.New(resize, posterize, upscale, sharpen) |
|
|
|
|
g = gift.New(resize, upscale, sharpen) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
out_img := image.NewNRGBA(g.Bounds(target_bounds)) |
|
|
|
|
@ -91,10 +94,12 @@ func SplitPathExt(path string) (string, string, bool) { |
|
|
|
|
return source_name, ext, found |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func RePrefixPath(path string, new_prefix string) string { |
|
|
|
|
func RePrefixPath(source string, path string, new_prefix string) string { |
|
|
|
|
split_path := UnfuckedPathSplit(path) |
|
|
|
|
split_source := UnfuckedPathSplit(source) |
|
|
|
|
tail := split_path[len(split_source) - 1:] |
|
|
|
|
|
|
|
|
|
prefixed_path := append([]string{new_prefix}, split_path...) |
|
|
|
|
prefixed_path := append([]string{new_prefix}, tail...) |
|
|
|
|
|
|
|
|
|
res := filepath.Join(prefixed_path...) |
|
|
|
|
return filepath.ToSlash(res) |
|
|
|
|
@ -134,7 +139,8 @@ func Included(config Settings, path string) bool { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func GetConversion(config Settings, path string) Conversion { |
|
|
|
|
path = RePrefixPath(path, "") |
|
|
|
|
path = strings.ToLower(RePrefixPath(config.Source, path, "")) |
|
|
|
|
|
|
|
|
|
for key, conversion := range config.Exceptions { |
|
|
|
|
match, err := regexp.MatchString(key, path) |
|
|
|
|
if err != nil { log.Fatalf("problem matching regex %s: %v", key, err) } |
|
|
|
|
@ -166,7 +172,8 @@ func RenderImages(config Settings, force bool) error { |
|
|
|
|
path = filepath.ToSlash(path) |
|
|
|
|
|
|
|
|
|
if !d.IsDir() && Included(config, path) { |
|
|
|
|
target := RePrefixPath(path, config.Target) |
|
|
|
|
// have to lowercase the target path to avoid windows issues
|
|
|
|
|
target := strings.ToLower(RePrefixPath(config.Source, path, config.Target)) |
|
|
|
|
|
|
|
|
|
err = MkdirPath(target) |
|
|
|
|
if err != nil { |
|
|
|
|
@ -182,11 +189,11 @@ func RenderImages(config Settings, force bool) error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if force || HasChanged(path_info, target) { |
|
|
|
|
// have to lowercase the target path to avoid windows issues
|
|
|
|
|
JankImage(convert, path, strings.ToLower(target)) |
|
|
|
|
fmt.Println("JANKIFY: ", path, "->", target) |
|
|
|
|
JankImage(convert, path, target) |
|
|
|
|
} else { |
|
|
|
|
fmt.Println("UNCHANGED: ", path, "->", target) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
fmt.Println("SKIP:", path) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|