Copy and Paste Code index.php file
<?php
include('header.php');
include('functions.php');?>
<title> PHPWRITTER-WATERMARK </title>
<?php include('container.php');?>
<div class="container">
<h2> PHPWRITTER-WATERMARK-IMAGES</h2>
<br>
<br>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="image" value=""><br>
<select name="image_upload">
<option value="">Water Mark Type</option>
<option value="text_watermark"> PHPWRITTER-Text-Mark</option>
<option value="image_watermark"> PHPWRITTER-Image-Mark</option>
</select>
<input type="submit" value="Upload"><br>
</form>
//http://phpwritter.blogspot.in//
<?php
if(isset($_FILES['image']['name'])){
switch($_FILES['image']['type']){
case 'image/jpeg':
case 'image/jpg':
if(getimagesize($_FILES['image']['tmp_name']) < (1024*1024*1024*1024)){
echo 'Image size is greater than 2MB';
} elseif(empty($_POST['image_upload'])){
echo 'Please select watermark type';
} else {
list($txt, $ext) = explode(".", $_FILES['image']['name']);
$file_name = "images/watermark.".$ext;
$upload = copy($_FILES['image']['tmp_name'], $file_name);
if($upload == true){
if($_POST['image_upload'] == 'text_watermark'){
$watermark = "phpwritter.blogspot.in";
addTextWatermark($file_name, $watermark, $file_name);
} elseif($_POST['image_upload'] == 'image_watermark'){
$WaterMark = 'watermark.png';
addImageWatermark ($file_name, $WaterMark, $file_name, 50);
}
echo '<br><img src="'.$file_name.'" class="preview" width="1000"><br>';
} else {
echo 'Error uploading image';
}
}
break;
default:
echo 'Please select jpeg or jpg type file for upload';
}
}
?>
<br>
<br>
<div style="margin:10px 0px 0px 0px;">
<a class="btn btn-default read-more" style="background:#ddd;color:white" href="" title="">Submit</a>
</div>
</div>
<!----http://phpwritter.blogspot.in// ------>
----------------------------------------------------------------------------------------------------------------------
Create function.php file and Copy this Code or Paste Function .php File
<?php
//http://phpwritter.blogspot.in//
function addTextWatermark($src, $watermark, $save=NULL) {
list($width, $height) = getimagesize($src);
$image_color = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($src);
imagecopyresampled($image_color, $image, 0, 0, 0, 0, $width, $height, $width, $height);
$txtcolor = imagecolorallocate($image_color, 255, 255, 255);
$font = 'MONOFONT.TTF';
$font_size = 50;
imagettftext($image_color, $font_size, 0, 50, 150, $txtcolor, $font, $watermark);
if ($save<>'') {
imagejpeg ($image_color, $save, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($image_color, null, 100);
}
imagedestroy($image);
imagedestroy($image_color);
}
//http://phpwritter.blogspot.in//
function addImageWatermark($SourceFile, $WaterMark, $DestinationFile=NULL, $opacity) {
$main_img = $SourceFile;
$watermark_img = $WaterMark;
$padding = 5;
$opacity = $opacity;
//http://phpwritter.blogspot.in//
$watermark = imagecreatefrompng($watermark_img);
$image = imagecreatefromjpeg($main_img);
if(!$image || !$watermark) die("IMAGE IS NOT WORKING");
$watermark_size = getimagesize($watermark_img);
$watermark_width = $watermark_size[0];
$watermark_height = $watermark_size[1];
$image_size = getimagesize($main_img);
$dest_x = $image_size[0] - $watermark_width - $padding;
$dest_y = $image_size[1] - $watermark_height - $padding;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity);
if ($DestinationFile<>'') {
imagejpeg($image, $DestinationFile, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($image);
}
imagedestroy($image);
imagedestroy($watermark);
}
?>
<!----http://phpwritter.blogspot.in// ------>
RESULT -
0 comments:
Post a comment