![]() But still most of online services have file size restrictions. Print("Resizing ratio:", args.The speed of innovation in smartphone and digital video recoder, especially HD, 4K and 8K camera, or DJI drones, high resolution and high quality of photos and videos are produced every day. Parser.add_argument("-hh", "-height", type=int, help="The new height for the image, make sure to set it with the `width` parameter") ![]() Parser.add_argument("-w", "-width", type=int, help="The new width image, make sure to set it with the `height` parameter") Parser.add_argument("-r", "-resize-ratio", type=float, help="We are resizing ratio from 0 to 1, setting to 0.5 will multiply width & height of the image by 0.5. Parser.add_argument("-q", "-quality", type=int, help="Quality ranging from a minimum of 0 (worst) to a maximum of 95 (best). Parser.add_argument("-j", "-to-jpg", action="store_true", help="Whether to convert the image to the JPEG format") Parser.add_argument("image", help="Given image to compress and/or resize") ![]() Parser = argparse.ArgumentParser(description="Python script for compressing and resizing images") New_filename = f"% of the original image size.") # make new filename appending _compressed to the original file name Img = img.resize((image_width, height_width), Image.ANTIALIAS)įilename, ext = os.path.splitext(image_name) # if image_width and height_width are set, resize with them instead Img = img.resize((int(img.size * new_size_ratio), int(img.size * new_size_ratio)), Image.ANTIALIAS) Print(" Size before compression:", get_size_format(image_size)) # printting the size before compression/resizing # getting the original image size in bytes Python Tutorial Python Features Python History Python Applications Python Install Python Example Python Variables Python Data Types Python Keywords Python Literals Python Operators Python Comments Python If else Python Loops Python For Loop Python While Loop Python Break Python Continue Python Pass Python Strings Python Lists Python Tuples Python List Vs Tuple Python Sets Python Dictionary Python Functions Python Built-in Functions Python Lambda Functions Python Files I/O Python Modules Python Exceptions Python Date Python Regex Python Sending Email Read CSV File Write CSV File Read Excel File Write Excel File Python Assert Python List Comprehension Python Collection Module Python Math Module Python OS Module Python Random Module Python Statistics Module Python Sys Module Python IDEs Python Arrays Command Line Arguments Python Magic Method Python Stack & Queue PySpark MLlib Python Decorator Python Generators Web Scraping Using Python Python JSON Python Itertools Python Multiprocessing How to Calculate Distance between Two Points using GEOPY Gmail API in Python How to Plot the Google Map using folium package in Python Grid Search in Python Python High Order Function nsetools in Python Python program to find the nth Fibonacci Number Python OpenCV object detection Python SimpleImputer module Second Largest Number in Pythonĭef compress_given_img(image_name, new_size_ratio=0.9, quality=90, image_width=None, height_width=None, to_jpg=True):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |