Skip to content

Commit

Permalink
Add option to disable tile resize filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 20, 2019
1 parent 954f4a6 commit 7dcd0be
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
DEFAULT_ADD_RAINBOWS = True

class Wallpaperer():
def __init__(self, wallpaper_width=1920, wallpaper_height=1080, tile_width=64, tile_height=64, verbose=False):
def __init__(self, wallpaper_width=1920, wallpaper_height=1080, tile_width=64, tile_height=64, verbose=False, smooth=True):
self.found_count = 0
self.wallpaper_width = wallpaper_width
self.wallpaper_height = wallpaper_height
self.tile_width = tile_width
self.tile_height = tile_height
self.verbose = verbose
self.formats = ('png', 'jpg', 'jpeg')
self.smooth = smooth

@property
def tiles_x(self):
Expand All @@ -47,7 +48,7 @@ def place_tiles(self, directory="tiles"):
self.found_count = len(tiles)

for tile in tiles:
img = Image.open(tile).convert("RGBA").resize((self.tile_width, self.tile_height), resample=Image.BILINEAR)
img = Image.open(tile).convert("RGBA").resize((self.tile_width, self.tile_height), resample=Image.BILINEAR if self.smooth else Image.NEAREST)

filename = os.path.split(tile)[-1]
fname, fext = filename.split('.')
Expand Down Expand Up @@ -96,6 +97,7 @@ def has_slot(self, grid):
parser.add_argument('--width', type=int, help='wallpaper width in pixels (default: {}px)'.format(DEFAULT_WIDTH), default=DEFAULT_WIDTH)
parser.add_argument('--height', type=int, help='wallpaper height in pixels (default: {}px)'.format(DEFAULT_HEIGHT), default=DEFAULT_HEIGHT)
parser.add_argument('--insanity', action='store_true', help='use a proper coordinate system for geniuses! (default: your fault!)', default=False)
parser.add_argument('--nearest', action='store_true', help='use nearest filtering to resize tiles', default=False)
parser.add_argument('--filename', type=str, help='filename to save as (defaut: wallpaper.png)', default='wallpaper.png')

args = parser.parse_args()
Expand All @@ -108,7 +110,8 @@ def has_slot(self, grid):
wallpaper_width=args.width,
wallpaper_height=args.height,
tile_width=args.tilewidth,
tile_height=args.tileheight)
tile_height=args.tileheight,
smooth=not args.nearest)

wallpaper = Image.new("RGBA", (args.width, args.height), (0, 0, 0, 255))

Expand Down

0 comments on commit 7dcd0be

Please sign in to comment.