Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit45ba1f8

Browse files
committed
add removing metadata from images tutorial
1 parent80950fd commit45ba1f8

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
266266
-[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))
267267
-[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))
268268
-[How to Compress Images in Python](https://www.thepythoncode.com/article/compress-images-in-python). ([code](python-for-multimedia/compress-image))
269+
-[How to Remove Metadata from an Image in Python](https://thepythoncode.com/article/how-to-clear-image-metadata-in-python). ([code](python-for-multimedia/remove-metadata-from-images))
269270

270271
-###[Web Programming](https://www.thepythoncode.com/topic/web-programming)
271272
-[Detecting Fraudulent Transactions in a Streaming Application using Kafka in Python](https://www.thepythoncode.com/article/detect-fraudulent-transactions-with-apache-kafka-in-python). ([code](general/detect-fraudulent-transactions))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#[How to Remove Metadata from an Image in Python](https://thepythoncode.com/article/how-to-clear-image-metadata-in-python)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Import necessary libraries.
2+
importargparse
3+
fromPILimportImage
4+
5+
6+
# Function to clear Metadata from a specified image.
7+
defclear_all_metadata(imgname):
8+
9+
# Open the image file
10+
img=Image.open(imgname)
11+
12+
# Read the image data, excluding metadata.
13+
data=list(img.getdata())
14+
15+
# Create a new image with the same mode and size but without metadata.
16+
img_without_metadata=Image.new(img.mode,img.size)
17+
img_without_metadata.putdata(data)
18+
19+
# Save the new image over the original file, effectively removing metadata.
20+
img_without_metadata.save(imgname)
21+
22+
print(f"Metadata successfully cleared from '{imgname}'.")
23+
24+
# Setup command line argument parsing
25+
parser=argparse.ArgumentParser(description="Remove metadata from an image file.")
26+
parser.add_argument("img",help="Image file from which to remove metadata")
27+
28+
# Parse arguments
29+
args=parser.parse_args()
30+
31+
# If an image file is provided, clear its metadata
32+
ifargs.img:
33+
clear_all_metadata(args.img)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pillow

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp