php image display a mess of solutions: 1, open the corresponding PHP code file; 2, in the page header plus "header ("Content-Type: image/jpg");" code to declare the image type can be.

How to display a mess of php images?

Image display messy code:

The following code can be added to the page header and is used to declare the image type.

1

2

<?php

header("Content-Type:image/jpg");//Image encoding settings

 

PHP to add coding to images

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

function setWater($dst_path, $save_path, $text)

{

    // Example of creating an image

    $dst = imagecreatefromstring(file_get_contents($dst_path));

 

    // Text Style

    $font    = realpath('./font/arial.ttf');

    $black    = imagecolorallocate($dst, 255, 255, 255);    //Font color

 

    // Add text

    imagefttext($dst, 22, 0, 20, 40, $black, $font, $text);

 

    // Output images

    list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);

 

    switch ($dst_type) {

        //GIF

        case 1:

            //header('Content-Type: image/gif');

            $save_path = $save_path . $text .'.gif';

            imagegif($dst, $save_path, 90);

            break;

        //JPG

        case 2:

            //header('Content-Type: image/jpeg');

            $save_path = $save_path . $text .'.jpg';

            imagejpeg($dst, $save_path, 90);

            break;

        //PNG

        case 3:

            //header('Content-Type: image/png');

            $save_path = $save_path . $text .'.png';

            imagepng($dst, $save_path, 90);

            break;

        default:

            break;

    }

 

    imagedestroy($dst);

 

}

 

$dst_path = '7002.jpg';

//$text     = '7001';

//setWater($dst_path, './tmppic/', $text);

 

for ($i=1; $i<=240; $i++) {

    $text = '00'. $i;

    $text = substr($text, -3);

     

    setWater($dst_path, './tmppic/', $text);

}

 

echo('ok');

Related articles

php can't load js css

php can not load js css solution: 1, check the correct path to load; 2, prohibit the use of absolute path; 3, use relative path to load the file can be.

php how to check user ip

php query user ip method: 1, get user ip by "$_SERVER["REMOTE_ADDR"]" way; 2, get user ip by "($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];" to get the user ip and so on.

How to invert a string by word in php

Inversion methods: 1. use "explode(' ',$str)" statement to convert string to array; 2. use "array_reverse($arr)" statement to invert the array and return the array in the reverse order of elements; 3. use "implode(' ',$arr)" statement to convert the inver

php get maximum value in several numbers

In php, you can use the max() function to get the maximum value among several numbers. The function works by calculating and returning the maximum value among several specified values, with the syntax "max(value1,value2,...) ;".

How to convert php image to base64

php image to base64 method: 1, get an image address; 2, through the "chunk_split(base64_encode($gambar));" method to convert the image to base64 string format can be.

How to merge arrays in PHP

How to merge arrays in PHP? To do this we need to use the array_merge function and the array_merge_recursive function. Here we will introduce these two functions separately.

How to compare strings in PHP?

String is an important data type in PHP, which how to compare strings is also very common in our development work, there are many kinds of comparison methods to compare strings, here we will introduce the more commonly used several comparison methods.

The difference between jumps and redirects in PHP

Difference: 1. Jump is the current URL request success, re-request a new URL; while redirect is the current URL is invalid, was redirected to a new URL. 2. In the jump, the browser will record the current URL and the new URL to the history; while redirect

How to merge elements of different arrays in php

php merge different array elements method: 1, create a PHP sample file; 2, by "array_keys(array_flip($a) + array_flip($b) + array_flip($c));" way to multiple arrays can be merged and de-weighted.