gundambison

perbaikan 48

May 3rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 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.     imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
  79.     imagejpeg($image, $new_image_name, 100);
  80.     imagedestroy($image);
  81.     unlink($oldimage_name);
  82.  
  83.     return true;
  84. }
  85. ?>
  86.     </form>
  87.  
  88.     <script>
  89.        *//alert
  90.         window.setTimeout(function(){
  91.         $(".alert").fadeTo(500,0).slideUp(500,function(){
  92.             $(this).remove();
  93.             });
  94.         },5000);
  95.         </script>
  96.  
  97. <script src="asset/js/jquery.min.js"></script>
  98. <script src="asset/js/popper.min.js"></script>
  99. <script src="asset/js/bootstrap.min.js"></script>
Advertisement
Add Comment
Please, Sign In to add comment