You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1
Original file line number
Diff line number
Diff line change
@@ -186,5 +186,6 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
186
186
-[How to Extract Video Metadata in Python](https://www.thepythoncode.com/article/extract-media-metadata-in-python). ([code](python-for-multimedia/extract-video-metadata))
187
187
-[How to Record a Specific Window in Python](https://www.thepythoncode.com/article/record-a-specific-window-in-python). ([code](python-for-multimedia/record-specific-window))
188
188
-[How to Add Audio to Video in Python](https://www.thepythoncode.com/article/add-audio-to-video-in-python). ([code](python-for-multimedia/add-audio-to-video))
189
+
-[How to Compress Images in Python](https://www.thepythoncode.com/article/compress-images-in-python). ([code](python-for-multimedia/compress-image))
189
190
190
191
For any feedback, please consider pulling requests.
print("[+] Size after compression:", get_size_format(new_image_size))
61
+
# calculate the saving bytes
62
+
saving_diff=new_image_size-image_size
63
+
# print the saving percentage
64
+
print(f"[+] Image size change: {saving_diff/image_size*100:.2f}% of the original image size.")
65
+
66
+
67
+
if__name__=="__main__":
68
+
importargparse
69
+
parser=argparse.ArgumentParser(description="Simple Python script for compressing and resizing images")
70
+
parser.add_argument("image", help="Target image to compress and/or resize")
71
+
parser.add_argument("-j", "--to-jpg", action="store_true", help="Whether to convert the image to the JPEG format")
72
+
parser.add_argument("-q", "--quality", type=int, help="Quality ranging from a minimum of 0 (worst) to a maximum of 95 (best). Default is 90", default=90)
73
+
parser.add_argument("-r", "--resize-ratio", type=float, help="Resizing ratio from 0 to 1, setting to 0.5 will multiply width & height of the image by 0.5. Default is 1.0", default=1.0)
74
+
parser.add_argument("-w", "--width", type=int, help="The new width image, make sure to set it with the `height` parameter")
75
+
parser.add_argument("-hh", "--height", type=int, help="The new height for the image, make sure to set it with the `width` parameter")
0 commit comments