Skip to content

Instantly share code, notes, and snippets.

@Mossman1215
Created October 24, 2021 21:05
Show Gist options
  • Save Mossman1215/79fc0b8163e4bc2eef0a0942326f3133 to your computer and use it in GitHub Desktop.
Save Mossman1215/79fc0b8163e4bc2eef0a0942326f3133 to your computer and use it in GitHub Desktop.
#requires pyvips and ruby-image-processing on ubuntu
import pyvips
import argparse
import pathlib
parser = argparse.ArgumentParser(description='resize images ')
parser.add_argument('images', metavar='file', nargs='+',
help='paths to files to shrink')
args = parser.parse_args()
for filepath in args.images:
image = pyvips.Image.new_from_file(filepath, access='sequential')
image = image.colourspace('srgb')
image = image.resize( 0.5 )
source_path = pathlib.Path(filepath)
new_name = source_path.parent.joinpath(source_path.name.replace(source_path.suffix,'')+'_smol'+source_path.suffix).as_posix()
image.write_to_file(new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment