Home > Backend Development > PHP Tutorial > Principle of watermarking pictures in PHP (super simple example code)_PHP tutorial

Principle of watermarking pictures in PHP (super simple example code)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:14:05
Original
960 people have browsed it

Text watermark:

Copy code The code is as follows:

$w = 80;
$h = 20;
$im = imagecreatetruecolor($w,$h);
$textcolor = imagecolorallocate($im, 123, 12, 255);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29 , $grey); //Draw a rectangle and fill it

// Write the string in the upper left corner of the image
imagestring($im, 3, 2, 3, "Hello world!", $textcolor );

// Output image
header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);

Image watermark

$groundImg = "DSC05940.jpeg";
$groundInfo = getimagesize($groundImg);
$ground_w = $groundInfo[0];
//print_r( $groundInfo);
$ground_h = $groundInfo[1];
switch($groundInfo[2]){
case 1:
$ground_im = imagecreatefromgif($groundImg);
break ;
case 2:
$ground_im = imagecreatefromjpeg($groundImg);
break;
case 3:
$ground_im = imagecreatefrompng($groundImg);
break;
}

$waterImg = "DSC05949.jpeg";
$imgInfo =getimagesize($waterImg);
$water_w = $imgInfo[0];
$water_w = $imgInfo[1 ];

switch($imgInfo[2]){
case 1:
$water_im = imagecreatefromgif($waterImg);
break;
case 2:
$ water_im = imagecreatefromjpeg($waterImg);
break;
case 3:
$water_im = imagecreatefrompng($waterImg);
break;
}
imagecopy($ground_im,$water_im ,100,100,0,0,500,500);
header("Content-type: image/jpeg");

imagejpeg($ground_im);

Merge images php provides Many functions: for example: imagecopymerge, imagecopyresized

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326347.htmlTechArticleText watermark: Copy the code code as follows: $w = 80; $h = 20; $im = imagecreatetruecolor($ w,$h); $textcolor = imagecolorallocate($im, 123, 12, 255); $white = imagecolorallocate($im, 25...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template