Home > Backend Development > PHP Problem > Learn about encapsulating watermark functions in PHP in one minute

Learn about encapsulating watermark functions in PHP in one minute

慕斯
Release: 2023-03-10 21:58:01
Original
1785 people have browsed it

We have learned so much about PHP in PHP. I don’t know how much you know about the encapsulated watermark function. I believe that a large number of people will not know this part of the knowledge. So don’t worry, this article will lead you to learn more about it. Understand this content deeply.

Related recommendations: Learn about encapsulating verification codes in PHP in one minute

Encapsulating watermark function:

Let’s create a file first, Then we first define a function, and then there are several resources that need to be written, and then give it a test by default, and then transparency, and then store space in time, and then we start further operations. The specific code is as follows:

Open the picture:

$sourceRes = open ($source) ;
var_dump ($source) ;
$waterRes=open ($water) ;
Copy after login

//Get the size of the picture and calculate the position

$sourceInfo=getimagesize ($source) ;
$waterInfo = getimagesize ($water) ;
Copy after login

Function to open the picture:

function open ($path)
{
Copy after login

Still defines a function, and then we need to pass a path, and then we determine whether it exists,

if (!file_exists ($path) ) {
exit('文件不存在') ;
$info=getimagesize ($path) ;
//var_dump($info) ;
switch ($info['mime']) (
  case ' image/jpeg' :
  case ' image/jpg' :
  case
  ' image/pjpeg' :
  $res=imagecreatefromjpeg ($path) ;
  break;
  case'image/png' :
  $res=imagecreatefrompng ($path) ;
  break ;
  case'image/gif' :
  $res = imagecreatefromgif ($path) ;
  break; .
  case'image/wbmp' :
  case ' image/bmp' :
  $res=imagecreatefromwbmp ($path) ;
  break;
  
}
}
Copy after login

//Calculate the position

switch ($position) {
  case1 :
  $x=0;
  $y-0;
  break;
  case 2 :
  $x=($sourceInfo[0] - $waterInfo[0]) / 2;
  $y=0;
  break;
  case 3 :
  $x=$sourceInfo[0] - $waterInfo[0];
  $y=O;
  break;
  caso 4 :
  $X=0;
  $y = ($sourceInfo[1] - $waterInfo[]) / 2;
  break;
  case 5 :
    $x =($sourceInfo[0] - $waterInfo[0]), / 2;
    2;
    $y = ($sourceInfo[1] - $waterInfo[1]) / 2;
    break;
    case 6: 
    $x = $sourceInfo[0] - $waterInfo[0];
    $y = ($sourceInfo[1] - $waterInfo[1]) / 2
    break;
    case 7 :
    $x-0;
    $y - $sourceInfo[1] - SwaterInfo[1];
    break;
    case 8 :
    $x=($sourceInfo[0] - $waterInfo[0]) / 2;
    $y = $sourceInfo[1] - $waterInfo[1];
    break;
    caso 9 :
    $x=$sourceInfo[0] - $waterInfo[0];
    $y = $sourceInfo[1] - $waterInfo[1];
    break;
    default :
    $x=mt_rand(0 ,$sourceInfo[0] - $waterInfo[0]) ;
    $y=mt_rand(0,$sourceInfo[1] - $waterInfo[1]) ;
    break;
Copy after login

//Use the value obtained by xy for use when merging two pictures

imagecopymerge () ;
Copy after login

Related learning video sharing:php video tutorial

The above is the detailed content of Learn about encapsulating watermark functions in PHP in one minute. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template