https://www.PrimeItHead.com
https://www.PrimeItHead.com
நாங்கள் php ஐ பயன்படுத்தி பல வெப் அப்ளிகேஷன் களை உருவாக்கி இருப்போம். and அவை வேலை செய்யும் அழகையும் ரசித்து இருப்போம் . அதே போல இன்றும் ஒரு சிறந்த Application உருவாக்கி பார்ப்போம் so Digital Watermarking to Hide Text Messages என்ற பதிவு வழங்குகின்றோம்.
நம்மிடம் உள்ள ஏதாவது Digital Documents க்கு actually (Image , Audio and Video) எது வேண்டுமானாலும் இருக்கட்டும். But அத்துடன் மறைமுகமாக நாம் ஏதாவது தகவலை பாதுகாப்பதற்க்கு இதை பயன் படுத்தலாம். so நமக்கு சில முக்கியமான தேவை பாடுகள் உள்ளன . First of all php பற்றிய அறிமுகம் நமக்கு தேவை. Actually Php தெரியாமல் நாம் ஏண்டா வாசிக்க போறோம் . அது தானே பாருங்களன் .
But இங்கே நாம் கொடுக்கும் Text ஆனது சாதாரணமாக பார்க்கும் பொழுது நமக்கு தெரியாது . Actually இதை பார்க்க சில தனிப்பட்ட Software உள்ளன But நமக்கு அதை Convert பண்ண கூடிய Software உள்ளது So நாம் பயம் கொள்ள தேவை இல்லை.
ஒரு தனிபட்ட நபர் ஏதாவது ஒரு Digital Documents இன் உரிமையாளர் என்றால் வேறு ஒரு நபர் அதற்க்கு உரிமை கோரலாம். and வேறு நபர்கள் அதை பிரதி எடுக்க முடியாது. Also ஏதாவது தனிபட்ட ரகசிய தகவல்களை மறைபதற்க்கு இதனை நாம் பயன்படுத்தலாம்.
Types of Watermarking
watermark/
├── index.php # Frontend form – இதுதான் Client பார்க்கும் Form ஆகும் .
├── encode.php # இங்கேதான் நாம் ரகசிய text ஐ மறைத்து அனுப்ப போகின்றோம் .
├── decode.php # Extract text from image ரகசிய text ஐ Decode பண்ணி எடுக்க போகின்றோம்
├── uploads/ # Uploaded and watermarked images நாம் அனுப்பும் டிஜிட்டல் documents அனைத்தும் இங்கேதான் save ஆகும்.
Step 1
முதலாவதாக நாம் Form ஐ உருவாக்க வேண்டும். இங்கு நான் Form ஐ சாதாரணமாக உருவாக்கி உள்ளேன். எந்த விதமான Style களும் உருவாக்க வில்லை . ( நீங்கள் தேவைபடும் போது உங்களுக்கு வேண்டிய Style களை css Or Bootstrap இல்லை என்றால் வேற ஏதேனும் css Framework கொண்டு உருவாக்கி கொள்ளுங்கள்) . இனி இந்த index. php இனுடய Code ஐ பார்ப்போம்.
<!DOCTYPE html>
<html>
<head>
<title>Text Watermarking</title>
</head>
<body>
<h2>Hide Text Message in Image</h2>
<form action=”encode.php” method=”post” enctype=”multipart/form-data”>
Select image: <input type=”file” name=”image”><br><br>
Secret Message: <input type=”text” name=”message”><br><br>
<input type=”submit” name=”submit” value=”Hide Message”>
</form>
<h2>Decode Text from Image</h2>
<form action=”decode.php” method=”post” enctype=”multipart/form-data”>
Select watermarked image: <input type=”file” name=”image”><br><br>
<input type=”submit” name=”decode” value=”Decode Message”>
</form>
</body>
</html>
மேலுள்ள Code ஆனது கீழே உள்ள Image இல் உள்ளது போலே அதன் Output இருக்கும் .
இங்கே 2 Form உருவாக்கபட்டுள்ளது 1. ரகசிய மாக மறைக்க (Hide Message) 2. மறைத்த Text ஐ திரும்ப பெற்று கொள்ள (Decode Message) . அடுத்ததாக Message Hide பண்ணுவதர்க்காக encode. php என்ற php ஐ உருவாக்க வேண்டும் . text ஐ மீள பெறுவதர்க்காக Decode. text என்பதை உருவாக்க வேண்டும்.
Encode. php இனுடய Code கீழ் வருமாறு .
<?php
function encodeMessage($imagePath, $message, $outputPath)
{
$img = imagecreatefrompng($imagePath); // only PNG for lossless embedding
$width = imagesx($img);
$height = imagesy($img);
$message .= "|END"; // delimiter
$bin = '';
for ($i = 0; $i < strlen($message); $i++) {
$bin .= str_pad(decbin(ord($message[$i])), 8, "0", STR_PAD_LEFT);
}
$bitIndex = 0;
for ($y = 0; $y < $height; $y++) {
for ($x = 0; $x < $width; $x++) {
if ($bitIndex >= strlen($bin)) break 2;
$rgb = imagecolorat($img, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$b = ($b & 0xFE) | $bin[$bitIndex]; // Embed 1 bit in blue channel
$bitIndex++;
$newColor = imagecolorallocate($img, $r, $g, $b);
imagesetpixel($img, $x, $y, $newColor);
}
}
imagepng($img, $outputPath);
imagedestroy($img);
}
if (isset($_POST['submit'])) {
$msg = $_POST['message'];
$imgName = $_FILES['image']['name'];
$tmp = $_FILES['image']['tmp_name'];
$path = "uploads/" . time() . "_encoded.png";
move_uploaded_file($tmp, $path);
encodeMessage($path, $msg, $path);
echo "<h3>Message hidden successfully!</h3>";
echo "<img src='$path' width='300'><br>";
echo "<a href='$path' download>Download Watermarked Image</a>";
}
and decode. php இனுடைய code கீழ் வருமாறு .
<?php
function decodeMessage($imagePath)
{
$img = imagecreatefrompng($imagePath);
$width = imagesx($img);
$height = imagesy($img);
$bin = '';
for ($y = 0; $y < $height; $y++) {
for ($x = 0; $x < $width; $x++) {
$rgb = imagecolorat($img, $x, $y);
$b = $rgb & 0xFF;
$bin .= ($b & 1);
}
}
$message = '';
for ($i = 0; $i < strlen($bin); $i += 8) {
$char = chr(bindec(substr($bin, $i, 8)));
$message .= $char;
if (strpos($message, "|END") !== false) break;
}
return str_replace("|END", "", $message);
}
if (isset($_POST['decode'])) {
$tmp = $_FILES['image']['tmp_name'];
$msg = decodeMessage($tmp);
echo "<h3>Decoded Message:</h3>";
echo "<p>$msg</p>";
}
and கட்டாயமாக நமக்கு upload என்ற பெயரில் Folder ஒன்று உருவாக்க வேண்டும். Index.php யில் நாம் தேவையான image select செய்து நமது Message ஐ type செய்ய வேண்டும் . அதன் பின்னர் டெக்ஸ்ட் hide பண்ணிய image ஐ download செய்து Decode பண்ணினால் நாம் கொடுத்த text வெளியாகிவிடும். அவளவுதான் .
இதன் பின்னர் இன்னும் நிறைய Validation வேலை செய்ய இருக்கின்றது. அதையும் நாம் உருவாக்கி கொள்ளலாம் . அதாவது நாம் இன்னும் பல Security Updates கொடுக்கலாம்.
Also You Can Read Web-Based Movie Portal Using TMDb API and PHP . Also You Can Download the Code from Github.