gundambison

perbaikan 49

May 3rd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. $demo_image= "";
  4. $font_path = "./gilsanub.ttf"; // Font file
  5. $font_size = 30; // in pixcels
  6. $water_mark_text_2 = "Tes"; // Watermark Text
  7.  
  8. if(isset($_POST['createmark']) and $_POST['createmark'] == "Submit")
  9. {
  10.     $path = "uploads/";
  11.     $valid_formats = array("jpg", "bmp","jpeg");
  12.     $name = $_FILES['imgfile']['name'];
  13.     if(strlen($name))
  14.     {
  15.         list($txt, $ext) = explode(".", $name);
  16.         if(in_array($ext,$valid_formats) && $_FILES['imgfile']['size'] <= 256*1024)
  17.         {
  18.             $upload_status = copy($_FILES['imgfile']['tmp_name'], $path.$_FILES['imgfile']['name']);
  19.             if($upload_status){
  20.                 $new_name = $path.time().".jpg";
  21.                 // Here you have to user functins watermark_text or watermark_image
  22.                 if(watermark_text($path.$_FILES['imgfile']['name'], $new_name)){
  23.                     $demo_image = $new_name;
  24.                 }else{
  25.                     $msg="File Error.";
  26.                 }
  27.             }
  28.         }
  29.         else{
  30.             $msg="File size Max 256 KB or Invalid file format.";
  31.         }
  32.    
  33.     }else{
  34.         $msg='no name';
  35.     }
  36. }else{
  37.     //var_dump($_POST);
  38. }
  39.  
  40.  
  41. ?>
  42.  
  43.  
  44. <center>TEXT WATERMARK</center>
  45. <h2></h2>
  46. <form name="imageUpload" method="post" enctype="multipart/form-data" >
  47. <center>Upload Image
  48. Image :<input type="file" name="imgfile" /><br />
  49. <input type="submit" name="createmark" value="Submit" /></center>
  50.  
  51.  
  52.  
  53. <?php
  54. if(isset($msg)){
  55.     echo "<div>$msg</div>";
  56. }
  57.  
  58. if(!empty($demo_image))
  59. echo '<img src="'.$demo_image.'" />';
  60. ?>
  61. </form>
  62. <?php
  63.  
  64. function watermark_text($oldimage_name, $new_image_name)
  65. {
  66.     global $font_path, $font_size, $water_mark_text_2;
  67.     if(!is_file($font_path)){
  68.         //echo ('==no font=='.$font_path);
  69.         return FALSE;
  70.     }
  71.  
  72.     list($owidth,$oheight) = getimagesize($oldimage_name);
  73.     $width = $height = 300;
  74.     $image = imagecreatetruecolor($width, $height);
  75.     $image_src = imagecreatefromjpeg($oldimage_name);
  76.     imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
  77.     $blue = imagecolorallocate($image, 79, 166, 185);
  78.  
  79.     try {
  80.         imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
  81.     }
  82.     //catch exception
  83.     catch(Exception $e)
  84.     {
  85.         $font_path = "C:/Windows/Fonts/";
  86.         $dh = opendir($font_path);
  87.         while (($file = readdir($dh)) !== FALSE) {
  88.             if (substr(strtolower($file), -4) != '.ttf') continue;
  89.             imagettftext(
  90.                 $image, $font_size, 0, 68, 190, $blue,
  91.                 "{$font_path}{$file}", $water_mark_text_2
  92.             );
  93.             break;
  94.         }
  95.  
  96.       //array imagefttext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text [, array $extrainfo ] )
  97.     }
  98.    
  99.     imagejpeg($image, $new_image_name, 100);
  100.     imagedestroy($image);
  101.     unlink($oldimage_name);
  102.    
  103.     return true;
  104. }
  105. ?>
  106.     </form>
  107.  
  108.     <script>
  109.        *//alert
  110.         window.setTimeout(function(){
  111.         $(".alert").fadeTo(500,0).slideUp(500,function(){
  112.             $(this).remove();
  113.             });
  114.         },5000);
  115.         </script>
  116.  
  117. <script src="asset/js/jquery.min.js"></script>
  118. <script src="asset/js/popper.min.js"></script>
  119. <script src="asset/js/bootstrap.min.js"></script>
Advertisement
Add Comment
Please, Sign In to add comment