SoftwareQuery
Home About Contact

How To Adding Text Watermark and Image Watermark IN PHP

 SoftwareQuery     No comments   


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 -

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

0 comments:

Post a comment

Donate

Translate

Popular Posts

  • How to Make Image Upload Code Using AJAX
    Direct Copy Paste PHP File  Image Upload Code -   <html> <head> <meta charset="utf-8"> <meta http-equi...
  • Best Useful Free Plugin to Make Wordpress Theme
    Meta Slider   - Meta Slider is that the initial free possibility on today’s list. A premium version is additionally obtainable...
  • How To Install Magento on Localhost XAMPP OR WAMP SERVER
      Step-1 => Make Sure you have to install Latest Version of  Xampp server or Wamp server in your PC.   Step -2 => Go to Web Bro...
  • How To Intall Node.js Via Command On Window And Linux.
    Step-1 . Firstly We have to go official website of https://nodejs.org/en/ then download the latest version of Nodejs zi...
  • How to Set up Amazon Affiliate Marketing Account to Earn Money
    Amazon Associates is a  marketing of Amazon company. It is allowed to youtube channel owner, Social Media pages owner and any type...
  • How To Create Custom Pagination In WordPress
    Hello, Friend's in this post we are creating a custom code of Pagination in WordPress. It is very easy to put this code any custom...
  • How To Scrape Data From Website Url Using Php.
    Q. why using a Scraping. If we want to get data of another website then using web scraping. It is using a PHP HTML Dom parser library ...
  • How To Install Wordpress in Xampp Server And Wamp Server
      Step 1st  -      Install WampServer or Xampp Server.                                                                               ...
  • How to create facebook share and like button for webpage
    Step-1 . Go to web browser type google and write facebook sharing button click this URL or open this URL.                     Ref URL:...
  • How to create Database Connection with ENCRYPT Password in Php
    <?php  $username = $_POST['username'];   $email = $_POST['email'];  $psw = password_hash($_POST['psw'], PA...

Home

This blog Is very help full for beginner coder,if you want to learn new things definitely this Blog is very
helpful for you guys.

Followers

Contact form

Name

Email *

Message *

Blog

  • Home
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
  • Terms&Conditions

NewsLetter

Copyright © SoftwareQuery | Powered by softwarequery
Design by ShubhamTiwari | Theme by softwarequery.com | Distributed By softwarequery/