|
|
|
|
@ -41,15 +41,36 @@ func SaveImage(filename string, img image.Image) { |
|
|
|
|
|
|
|
|
|
func JankImage(settings Conversion, in_file string, out_file string) { |
|
|
|
|
src := LoadImage(in_file) |
|
|
|
|
bounds := src.Bounds() |
|
|
|
|
src_bounds := src.Bounds() |
|
|
|
|
target_bounds := src_bounds |
|
|
|
|
|
|
|
|
|
resize := gift.Resize(bounds.Max.X / settings.PixelWidth, 0, gift.NearestNeighborResampling) |
|
|
|
|
if settings.Width > 0 { |
|
|
|
|
target_bounds.Max.X = settings.Width |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if settings.Height > 0 { |
|
|
|
|
target_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(bounds, settings.PixelWidth) |
|
|
|
|
upscale := filters.Upscale(target_bounds, settings.PixelWidth) |
|
|
|
|
sharpen := gift.UnsharpMask(1, 1, 0) |
|
|
|
|
|
|
|
|
|
g := gift.New(resize, posterize, upscale, sharpen) |
|
|
|
|
out_img := image.NewNRGBA(g.Bounds(bounds)) |
|
|
|
|
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) |
|
|
|
|
} else { |
|
|
|
|
g = gift.New(resize, posterize, upscale, sharpen) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
out_img := image.NewNRGBA(g.Bounds(target_bounds)) |
|
|
|
|
g.Draw(out_img, src) |
|
|
|
|
|
|
|
|
|
SaveImage(out_file, out_img) |
|
|
|
|
@ -113,6 +134,7 @@ func Included(config Settings, path string) bool { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func GetConversion(config Settings, path string) Conversion { |
|
|
|
|
path = RePrefixPath(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) } |
|
|
|
|
@ -141,6 +163,8 @@ func HasChanged(old_info fs.FileInfo, new_path string) bool { |
|
|
|
|
func RenderImages(config Settings, force bool) error { |
|
|
|
|
err := filepath.WalkDir(config.Source, |
|
|
|
|
func(path string, d fs.DirEntry, err error) error { |
|
|
|
|
path = filepath.ToSlash(path) |
|
|
|
|
|
|
|
|
|
if !d.IsDir() && Included(config, path) { |
|
|
|
|
target := RePrefixPath(path, config.Target) |
|
|
|
|
|
|
|
|
|
|