From: David Polakovic Date: Fri, 18 Jul 2025 23:47:41 +0000 (+0200) Subject: script can now find picture in full path, fixed README.txt X-Git-Url: https://git.dpolakovic.space/?a=commitdiff_plain;p=tti-writer script can now find picture in full path, fixed README.txt --- diff --git a/README.txt b/README.txt index a3151b3..4fa7e39 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -SHMÚ fetch +Text-to-image (tti) writer The least significant bit writer. copyright 2024, David Polakovic, licensed under GPLv3 @@ -6,12 +6,17 @@ ABOUT: This script encodes message into a pictures. It utilizes very common approach of writing information in the least significant bits of the image pixels. You can check your message by performing -a hexdump on the image. +a hexdump on the image or by opening the image in a text editor. HOW TO RUN: Navigate to the directory where you downloaded the script and then use: perl tti.pl [file] ... +example: + perl tti.pl flower.png This is the secret message. + +New file will be saved in the same directory as the original file, +with "-processed" handle. LICENSE: diff --git a/tti.pl b/tti.pl index 4f2e06a..64e84c5 100644 --- a/tti.pl +++ b/tti.pl @@ -8,25 +8,37 @@ if (@ARGV < 2) { } # save the filename -my $filename = $ARGV[0]; +my $file_name = $ARGV[0]; +my $file_extension; + +if ($file_name =~ /^(.+)(\.[^.]+)$/) { + $file_extension = $2; # ".jpg" + $file_name = $1; # "flower" +} else { + # Handle case where there's no extension + $file_extension = ""; +} # save the message shift(@ARGV); my $message = join(" ", @ARGV); # create name for output file -my $new_filename = "processed_" . $filename; +my $new_file_name = $file_name . "-processed" . $file_extension; + +# revert back to original name once new name is created +$file_name = $file_name . $file_extension; # copy the file if ($^O eq 'MSWin32' or $^O eq 'MSWin64') { # for Windows - system("copy", $filename, $new_filename); + system("copy", $file_name, $new_file_name); } else { # for every other system - system("cp", $filename, $new_filename); + system("cp", $file_name, $new_file_name); } # write the message into new file -open my $fh, '>>:raw', $new_filename or die "Cannot open file: $!"; +open my $fh, '>>:raw', $new_file_name or die "Cannot open file: $!"; print $fh $message; close $fh;