찾다
php教程php手册PHP根据图片色界在不同位置加水印的方法

PHP根据图片色界在不同位置加水印的方法

Jun 13, 2016 am 08:59 AM
php다른위치추가하다그림존재하다방법양수표~의

PHP根据图片色界在不同位置加水印的方法

   本文实例讲述了PHP根据图片色界在不同位置加水印的方法。分享给大家供大家参考。具体实现方法如下:

  ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

function add_wm($nmw_water, $src_file, $output_file, $x, $y) {

if(file_exists($output_file))

return;

$w1 = MagickGetImageWidth($nmw_water);

$h1 = MagickGetImageHeight($nmw_water);

$nmw =NewMagickWand();

MagickReadImage($nmw, $src_file);

// 默认的加水印位置调整

$lt_w = 50;

$lt_h = 50;

if($x == 0){

$w = MagickGetImageWidth($nmw);

$h = MagickGetImageHeight($nmw);

$x = $w;

$y = $h;

}else{

// 根据具体情况调整

$lt_w = 30;

$lt_h = 40;

}

MagickCompositeImage($nmw, $nmw_water, MW_OverCompositeOp, $x - $w1 - $lt_w, $y - $h1 - $lt_h);

MagickWriteImage($nmw, $output_file);

DestroyMagickWand($nmw);

}

// 还是groovy的eachFileRecurse好用啊

function add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr) {

$dp = dir($to_dir);

while($file=$dp->read()){

if($file != '.' && $file != '..'){

if(is_dir($to_dir . '/' . $file)){

mkdir($output_dir . '/' . $file);

add_wm_recurse($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $arr);

}else{

if(!array_key_exists($to_dir . '/' . $file, $arr)){

continue;

}

$sub_arr = $arr[$to_dir . '/' . $file];

if($sub_arr){

$x = intval($sub_arr[0]);

$y = intval($sub_arr[1]);

add_wm($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $x, $y);

}

}

}

}

$dp->close();

}

$to_dir = './resized';

$output_dir = './output';

// 这个是我用java的ImageIO遍历图片像素获取的符合裤子颜色的区域的坐标array(posX, posY)

$arr = array(

array(50, 50)

);

$water = './water.png';

$nmw_water =NewMagickWand();

MagickReadImage($nmw_water, $water);

add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr);

DestroyMagickWand($nmw_water);

  希望本文所述对大家的php程序设计有所帮助。

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

SublimeText3 영어 버전

SublimeText3 영어 버전

권장 사항: Win 버전, 코드 프롬프트 지원!

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구