function-imagereverse-imagenegative

Gesponsorde koppelingen

PHP script bestanden

  1. function-imagereverse-imagenegative

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
function imagereverse( $path )
{

    # Read in image from $path
    if( strtolower( substr( $path, -3 ) ) == 'jpg' )
        $image = imagecreatefromjpeg( $path );
    elseif( strtolower( substr( $path, -3 ) ) == 'png' )
        $image = imagecreatefrompng( $path );
    else
        die( 'A non valid path has been given!' );
    
    # Get image dimensions
    $x = imagesx( $image );
    $y = imagesy( $image );
    
    # Create a new image
    $ip = imagecreatetruecolor( $x, $y );
    
    # Loop threw the whole height of the image
    for( $i = 0; $i < $y; $i++ )
    {

        # Loop threw the whole width of the image
        for( $j = 0; $j < $x; $j++ )
        {

            # Get the pixel color ( $x - 1 needs to be there cos of the imagestart @ 0,0 ;) )
            $c = imagecolorat( $image, ( $x - 1 ) - $j, $i );
            
            # Get the rgb values from color $c
            $r = ($c >> 16) & 0xFF;
            $g = ($c >> 8) & 0xFF;
            $b = $c & 0xFF;
            
            # Set the color
            $clr = imagecolorallocate( $ip, $r, $g, $b );
            
            # Set the pixel color in the new image
            imagesetpixel( $ip, $j, $i, $clr );
        }
    }

    
    # Output the reversed image
    header( 'Content-type: image/png' );
    imagepng( $ip );
    imagedestroy( $ip );
        imagedestroy( $image );
}

function
imagenegative( $path )
{

    # Read in image from $path
    if( strtolower( substr( $path, -3 ) ) == 'jpg' )
        $image = imagecreatefromjpeg( $path );
    elseif( strtolower( substr( $path, -3 ) ) == 'png' )
        $image = imagecreatefrompng( $path );
    else
        die( 'A non valid path has been given!' );
    
    # Get image dimensions
    $x = imagesx( $image );
    $y = imagesy( $image );
    
    # Create a new image
    $ip = imagecreatetruecolor( $x, $y );
    
    # Loop threw the whole height of the image
    for( $i = 0; $i < $y; $i++ )
    {

        # Loop threw the whole width of the image
        for( $j = 0; $j < $x; $j++ )
        {

            # Get the pixel color
            $c = imagecolorat( $image, $j, $i );
            
            # Get the rgb values from color $c
            $r = ($c >> 16) & 0xFF;
            $g = ($c >> 8) & 0xFF;
            $b = $c & 0xFF;
            
            # Subtract 255 to get the opposite color
            $r = abs( $r - 255 );
            $g = abs( $g - 255 );
            $b = abs( $b - 255 );
            
            # Set the color
            $clr = imagecolorallocate( $ip, $r, $g, $b );
            
            # Set the pixel color in the new image
            imagesetpixel( $ip, $j, $i, $clr );
        }
    }

    
    # Output the reversed image
    header( 'Content-type: image/png' );
    imagepng( $ip );
    imagedestroy( $ip );
    imagedestroy( $image );
}

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.