php教程 PHP源码 水印生成缩略图

水印生成缩略图

May 25, 2016 pm 04:58 PM

跳至

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

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

class InsertLogo//水印类

  {

   

    private $source;//主图片路径

    private $logo;//水印图片路径

    private $source_type;//主图片类型

    private $logo_type;//水印图片类型

    private $source_width;//主图片宽度

    private $source_height;//主图片高度

    private $logo_width;//水印图片宽度

    private $logo_height;//水印图片高度

    private $tinyImage_width;//略缩图宽

    private $tinyImage_height;//略缩图高

    private $newPicPath;//生成水印图片地址

    private $tinyImagePath;//生成略缩图存放路径

    function __construct($source,$logo)//传入图片路径

    {

      $this->source=$source;

      $info=GetImageSize($source);

      $this->source_width=$info[0];

      $this->source_height=$info[1];

      $this->source_type_id=$info[2];

      $this->source_type=$info['mime'];//其值 1 为 GIF 格式、 2 为 JPEG/JPG 格式、3 为 PNG 格式

      $this->logo=$logo;

      $info=GetImageSize($logo);

      $this->logo_width=$info[0];

      $this->logo_height=$info[1];

      $this->logo_type_id=$info[2];

      $thi->logo_type=$logo['mime'];

    }

    //1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP info[2]图片类型

    function JudgeTypeAndDeal($type,$source)//判断并处理,返回PHP可识别编码

    {

      if($type==1)//能处理的三种图片。可在上传类限制图片。

      {

        return ImageCreateFromGIF($source);

      }

      else if($type==2)

      {

        return ImageCreateFromJPEG($source);

      }

      else

      {

        return ImageCreateFromPNG($source);

      }

    }

    function CreateLogoImage()//生成水印图

    {

      $this->source=$this->JudgeTypeAndDeal($this->source_type_id,$this->source);//取得主图片编码

      $this->logo=$this->JudgeTypeAndDeal($this->logo_type_id,$this->logo);//取得水印编码

      $x=$this->source_width-$this->logo_width;

      $y=$this->source_height-$this->logo_height;

      $w=$this->logo_width;

      $h=$this->logo_height;

      /* echo "x=".$x;

      echo ",y=".$y;

      echo ",w=".$w;

      echo ",h=".$h; */

      ImageCopy($this->source,$this->logo,$x,$y,0,0,$w,$h)or die("fail to combine");

      $this->newPicPath='App/Upload/image/normal/1108000627/new.jpg';

      ImageJpeg($this->source,'new.jpg');

      rename('new.jpg',$this->newPicPath);//放到相应文件位置

    }   

    function CreateTinyImage()//生成略缩图,生成略缩图原则要控制图片比例,防止比例不协调,可改参数,尝试显示一部分原比例部分图片

    {

      $TinyImage=imagecreatetruecolor($this->source_width*0.3,$this->source_height*0.3);

      $this->source=$this->JudgeTypeAndDeal($this->source_type_id,$this->source);//取得主图片编码

      ImageCopyResized($TinyImage,$this->source,0,0,0,0,$this->source_width*0.3,$this->source_height*0.3,$this->source_width,$this->source_height) or die("fail");

      $this->tinyImagePath='App/Upload/image/tiny/1108000627/new.jpg';

      ImageJpeg($TinyImage,'new.jpg');

      rename('new.jpg',$this->tinyImagePath);//放到相应文件位置

    }

  }

  /*添加水印类生成略缩图类END*/

로그인 후 복사

                   

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 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 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

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

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)