Skip to content

Commit 877933c

Browse files
committed
add Hide text in img script
1 parent 2696ddd commit 877933c

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

Image_text_hider/img_text_hider.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import argparse
2+
from stegano import lsb
3+
import os
4+
5+
def hide_text_in_image(image_path, text, output_path):
6+
secret_image = lsb.hide(image_path, text)
7+
secret_image.save(output_path)
8+
9+
def reveal_text_from_image(image_path):
10+
try:
11+
secret_text = lsb.reveal(image_path)
12+
return (secret_text,1) #here 1 and 0 are used to enhance script quality
13+
except UnicodeDecodeError:
14+
return ("Unable to reveal text. Decoding error occurred.",0)
15+
except IndexError:
16+
return("Failed to find message in this file format, Try using different file format like png",0)
17+
except Exception as e:
18+
return(f"Contact the owner! {e}",0)
19+
20+
def main():
21+
print("\n[Welcome to Image text hider this script can hide text inside image]\n")
22+
print("To Hide the text inside image\nUSAGE: python img_text_hider.py hide img_name_with_path.jpg 'This is my secret msg' output_file_name.jpg\n")
23+
print("To reveal the hidden text inside image\nUSAGE: python img_text_hider.py reveal hidden_img_name.jpg\n")
24+
parser = argparse.ArgumentParser(description="Image Text Hider")
25+
26+
subparsers = parser.add_subparsers(dest="command", help="Available commands")
27+
28+
# Hide command
29+
hide_parser = subparsers.add_parser("hide", help="Hide text behind an image")
30+
hide_parser.add_argument("image", help="Path to the image file")
31+
hide_parser.add_argument("text", help="Text to hide")
32+
hide_parser.add_argument("output", help="Output path for the image with hidden text")
33+
34+
# Reveal command
35+
reveal_parser = subparsers.add_parser("reveal", help="Reveal text from an image")
36+
reveal_parser.add_argument("image", help="Path to the image file")
37+
38+
args = parser.parse_args()
39+
40+
if args.command == "hide":
41+
if os.path.exists(args.image):
42+
hide_text_in_image(args.image, args.text, args.output)
43+
print("Text hidden in the image successfully. Output image saved at", args.output)
44+
else:
45+
print("Image path you specified does not exist, Make sure to check image path and file name with extention")
46+
elif args.command == "reveal":
47+
if os.path.exists(args.image):
48+
49+
revealed_text,check = reveal_text_from_image(args.image)
50+
51+
if check==1: #if works out well
52+
print(f"Revealed text: [{revealed_text}]")
53+
else: # else display with error so that user can troubleshot the problem easily
54+
print(f'Error!,{revealed_text}')
55+
56+
else:
57+
print("Image path you specified does not exist, Make sure to check image path and file name with extention")
58+
59+
if __name__ == "__main__":
60+
main()

Image_text_hider/readme.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Image Text Hider
2+
3+
This script allows you to hide text inside an image using steganography. It utilizes the LSB (Least Significant Bit) technique to embed the text into the image without visibly altering the image.
4+
5+
## Requirements
6+
7+
- Python 3.6 or above
8+
- Install the required packages by running `pip install -r requirements.txt`.
9+
10+
## Usage
11+
12+
To hide text inside an image:
13+
python img_text_hider.py hide <image_path> <text> <output_path>
14+
15+
- `<image_path>`: Path to the image file.
16+
- `<text>`: Text to hide inside the image.
17+
- `<output_path>`: Output path for the image with hidden text.
18+
19+
To reveal the hidden text from an image:
20+
python img_text_hider.py reveal <image_path>
21+
22+
- `<image_path>`: Path to the image file with hidden text.
23+
24+
## Example
25+
26+
Hide text inside an image:
27+
python img_text_hider.py hide my_image.jpg "This is my secret message" output_image.jpg
28+
29+
Reveal the hidden text from an image:
30+
python img_text_hider.py reveal output_image.jpg

Image_text_hider/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
argparse
2+
stegano

0 commit comments

Comments
 (0)